3

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

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

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");

The second thread will call:

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

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

Is there in way to solve this?

3
  • what did u mean with 'parallel'? Do you men (brain example) system("1.exe 2.exe 3.exe");? or did you mean an asynchron call with own threads? May 11, 2014 at 16:38
  • 2
    In Windows? Use "start [options] program". May 11, 2014 at 16:38
  • You are aware of how to use backslashes (\) in string literals, don't you? May 11, 2014 at 16:44

2 Answers 2

4

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.

2
  • Assuming the OP is asking about Linux/Unix style operating system. May 11, 2014 at 17:51
  • But will it be possible to check the output of the separate executables? What would be wanted in my case is to have a way to read the output of the launched executables as well.
    – Michahell
    Feb 9, 2015 at 15:49
1
  • For windows: CreateProcess (see MSDN) function.
  • For *NIX: first, spwan a child with fork, then replace a child code with execXX (execl, execle, execlp, execv, execvp).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.