gpt4 book ai didi

c++ - 如何在C++中并行执行系统命令

转载 作者:搜寻专家 更新时间:2023-10-31 00:35:36 25 4
gpt4 key购买 nike

通常当我想从 C++ 代码运行可执行文件时。我只是使用代码:

system("path\to\the\executable param"); 

现在,我想并行运行可执行文件。我使用 2 个线程。第一个线程将调用:

system("path\to\the\executable param1");

第二个线程将调用:

system("path\to\the\executable param2");

但是它并没有像我预期的那样并行运行。

有什么办法可以解决吗?

最佳答案

您可以运行多个命令,如下所示:

system("path\\to\\the\\executable param1 &");
system("path\\to\\the\\executable param2");

这样两者将并行运行,并且您的程序不需要为此是多线程的。

关于c++ - 如何在C++中并行执行系统命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23595141/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com