开发者

With system() in C++ on Windows, why are two quotes required to invoke a program in another directory?

开发者 https://www.devze.com 2023-03-22 06:47 出处:网络
I have the find.exe program in my utils folder. This does not work: system(\"\\\"utils/find.exe\\\"\");

I have the find.exe program in my utils folder. This does not work:

system("\"utils/find.exe\"");

All I get is

'utils' is not recognized as an internal or external command,
operable开发者_StackOverflow社区 program or batch file.

However, for some reason this works:

system("\"\"utils/find.exe\"\"");

Echoing the single quoted string

system("echo \"utils/find.exe\"");

outputs

"utils/find.exe"

... so why do I need two quotes?


I assume you're on windows because you're trying to execute an .exe file. So, instead of writting "utils/find.exe", try to write "utils\find.exe". The delimiting character on windows is '\', so it probably sees "utils" as a command since '/' is ignored.


Perhaps system() is passing your command line to the shell, e.g. cmd.exe, which also needs quoting?


Even though you can use both / and \ as directory separators in Windows, the command processor will try to interpret anything starting with a / as a switch. Try this:

system("\"utils\\find.exe\"");
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号