user220878
user220878

Reputation:

Call an executable from C++, and wait until it is done, on Linux

I'm trying to write a program which, at some point, needs to invoke an external application via the system and wait until that other executable finishes. I pretty much want a C++ version of the python subprocess.call(...) method. I know that system() can invoke a command via the shell, but I don't know if it is able to block until the commands terminate. Anyone know the right way to do this?

I'm writing this for a Linux system, but if possible, I'd like it to be portable. Anyway, any help would be appreciated.

Upvotes: 4

Views: 8989

Answers (2)

Amish Programmer
Amish Programmer

Reputation: 2121

The popen command should work nicely for you: http://linux.die.net/man/3/popen

Upvotes: 3

Bogatyr
Bogatyr

Reputation: 19323

system() waits for the command to finish:

http://linux.die.net/man/3/system

system() executes a command specified in command by calling /bin/sh -c command, and returns after the command has been completed. During execution of the command, SIGCHLD will be blocked, and SIGINT and SIGQUIT will be ignored.

Upvotes: 10

Related Questions