我正在运行以下代码(在 Windows 7 上,如果它有所不同):
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);
运行时,控制台显示:
'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.
但是当我通过 QuickWatch 获取“temp”的值并将其粘贴到 CMD 时,它工作正常。这是怎么回事?
我应该指出,我附加到字符串的参数包含非拉丁字符。这可能与它有关吗?
最佳答案
您最好使用 CreateProcess()
来避免 cmd.exe 的引用 hell 。但是,如果您必须使用 system()
,您只需将 if 1==1
附加到命令的开头,这样它就不会为您删除引号。
system("if 1==1 \"C:\Program...");
有关此问题的更多信息,请运行 cmd.exe/?
并查找 /S
。
关于c++ - 系统函数似乎忽略了引号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4244095/