system函数 路径有空格 且 多个双引号,无法调用成功

_lee_chong _lee_chong 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

string cmdstr1 = "\"D:\\ff ff\\pscli.exe\"";
string cmdstr2 = "ping 192.168.20.1";
string cmdstr3 = "\"D:\\ff ff\\pscli.exe\" \"d:\\output\"";
string cmdstr4 = "\"ping\" \"192.168.20.1\" ";

cout << "1:" << endl;
system(cmdstr1.c_str());
cout << "2:" << endl;
system(cmdstr2.c_str());
cout << "3:" << endl;
system(cmdstr3.c_str());
cout << "4:" << endl;
system(cmdstr4.c_str());

system("PAUSE ");
return 0;



可以看到
1、有一对双引号,成功
2、无双引号,成功
3、4、 有两对双引号,失败;
但是如果直接cmd执行是可以的:
...全文

相关推荐

评论 6
收藏 已收藏
分享
返回顶部
_lee_chong
C++ 语言 65,213 成员 250,513 内容