Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 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?

like image 815
Christian Neverdal Avatar asked Oct 22 '25 21:10

Christian Neverdal


2 Answers

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?

like image 37
orip Avatar answered Oct 25 '25 11:10

orip



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!