I'm running the following code (on Windows 7, if it makes a difference):
char temp[20000];
sprintf_s(temp, 20000, "\"C:\\Program Files\\Mozilla Firefox\\firefox.exe\" \"http://www.tvtak.com/servlet/Gateway/?C=addShows&channel=%s&show=%s\"", _channels[chId], name);
system(temp);
On running, the console displays:
'C:\Program' is not recognized as an internal or external command, operable program or batch file.
'channel' is not recognized as an internal or external command, operable program or batch file.
'show' is not recognized as an internal or external command, operable program or batch file.
But when I get the value of 'temp' via QuickWatch and paste it to CMD, it works fine. What's going on here?
I should mention that the parameters I'm appending to the string contain non-latin characters. Could this have something to do with it?
You are better off with CreateProcess() to avoid cmd.exe's quoting hell. But if you must use system() you can simply append if 1==1 to the beginning of your command so it doesn't remove the quotes for you.
system("if 1==1 \"C:\Program...");
For more information about this issue, run cmd.exe /? and look for /S.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With