Search code examples
c++linuxexecute

Execute external command and wait for it to finish under Linux


Easy question: what is the easiest way to execute an external program (with parameters) from C++ (using g++ and Linux)? Is there an easier way rather than doing fork/exec and waiting? I just need to execute the command and wait for it to finish.


Solution

  • Kind of depends on how much you want to interact with the program.

    If not at all, you can easily just use system("....");

    If you want some I/O then you can use popen();

    And if even that is not enough, you will end up will fork(), exec(), wait(), dup() and other functions from this family.