系统调用出了什么问题

问题描述 投票:0回答:1

我一直在 Visual Studio 2022 中尝试下一个代码:

#include <string>
#include <iostream>
using namespace std;

int main()
{
    string Command1 = "cmd /c start ";
    string Command2 = "\"c:\\Program Files\\VideoLAN\\VLC\\vlc.exe\"";
    string myCommand = Command1 + Command2;
    //cout << myCommand;
    system(myCommand.c_str());
    return 0;
}

我期望执行命令行“cmd /c start c:\Program Files\VideoLAN\VLC lc.exe”结束程序 vlc 将运行。 似乎没有给出完整的命令。

我不知道我做错了什么。

visual-c++ system-calls
1个回答
0
投票

我发现我做错了什么, 我忘记在规则“string Command =”cmd /c start“;”中添加引号。 “start”的语法是:start ""

可以运行的完整 C++ 程序是:

#include <string>
#include <iostream>
using namespace std;

int main()
{
    string Command1 = "cmd /c start \"\" ";
    string Command2 = "\"c:\\Program Files\\VideoLAN\\VLC\\vlc.exe\"";
    string myCommand = Command1 + Command2;
    system(myCommand.c_str());
    return 0;
}
© www.soinside.com 2019 - 2024. All rights reserved.