如何在C ++中并行执行系统命令 [英] How to execute system command in parallel in c++

查看:290
本文介绍了如何在C ++中并行执行系统命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Normally when I want to run a executable from a c++ code. I just use the code:

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

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

Now, I want to run the executable file in parallel. I use 2 threads. The first thread will call:

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

第二个线程将调用:

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

但是,它并没有像我期望的那样并行运行.

However it doesn't run in parallel as I expect.

有办法解决这个问题吗?

Is there in way to solve this?

推荐答案

您可以运行以下多个命令:

You can run multiple commands as below:

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

这样,两者都可以并行运行,并且您的程序不需要为此使用多线程.

This way both will run in parallel, and your program doesn't need to be multi-threaded for this.

这篇关于如何在C ++中并行执行系统命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆