More specifically, I would like a function that can call an executable, like system(), but does not take control away from the program calling the executable. With system(), the program hangs up until the executable called by system finishes running. Is there a function that will call and executable but then keep running?
Or even more specifically, I would like to write a C++ program that can call an executable, call it "bob.exe", and then terminate, even though bob.exe is still running. System() obviously won't let me do this.
I use:
http://www.cplusplus.com/reference/clibr...
as a reference.
In C++, the system() function can call an executable. Are there other similar functions?
You can try using execl, or a similar function (execlp, execv, etc.) to run your program. However, since execl replaces the current process with the executed program, you'll want to use fork to create a child process which will be replaced instead.
For example:
int main()
{
int pid = fork();
if ( pid == 0 ) {
/* child process */
execlp("bob.exe", "bob.exe", NULL);
}
return 0;
}
EDIT:
In Windows, you can use CreateProcess() to call another program, which will return without waiting. The syntax is a little more complicated than fork(), so I don't remember it off the top of my head. ^_^
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment