在windows中,调用system去执行命令,但是因为命令中包含空格
c:\Program Files\path\to\some.exe --config c:\Program Files\path\to\some.conf
在CMD中我们可以
"c:\Program Files\path\to\some.exe" --config "c:\Program Files\path\to\some.conf"
但是在c++中这样调用,却是失败的
string sCmd("\"c:\Program Files\path\to\some.exe\" --config \"c:\Program Files\path\to\some.conf\"");
system(sCmd.c_str());
要这样,再在外面加一层双引号包含整个命令
string sCmd("\"\"c:\Program Files\path\to\some.exe\" --config \"c:\Program Files\path\to\some.conf\"\"");
system(sCmd.c_str());
参考
- 相关文章