Skip to main content
GameDev.net gamedev.net
🔒 Locked

Program that executes another Program

Started by Funkymunky Jan 3, 2009 at 1:17 PM 2 replies 1k views
Original Post
Funkymunky
Funkymunky
I'm writing a program that's ultimate goal is to launch another program with a filename. It is a fullscreen menu of filenames, basically, and when you select one i call the system command to execute a command line program with the filename. This is being done on a Debian PC with the GNU compiler, with both programs using SDL to set the video mode and draw to the screen. My program initially sets the video mode to 640x480x32, and the program i launch uses that also. I have a state machine in the file selector program which enters an idle loop after launching the program. I was hoping that by just calling the command line program it would start on top of my program, leaving mine idle in the background, and not need to change video modes. Instead, it hangs and i have to close it down. What would be the best method for accomplishing this, then?
rip-off
rip-off
You could pipe(), fork() and exec(), communicating asynchronously with the sub-process through the pipe. The problem with system() is that it is a blocking call, your original program cannot proceed in the background (without threading anyway).

We might be better able to give hints if we had some idea of what the background process was doing.
Funkymunky
Funkymunky
hmmm. well I actually kind of want it to be blocked... I want my program to call the other program with some command line arguments, and then i want that program to take over. I don't want my program to take up any system resources until the program it called terminates.
the_edd
the_edd
Quote:
Original post by Funkymunky
hmmm. well I actually kind of want it to be blocked... I want my program to call the other program with some command line arguments, and then i want that program to take over. I don't want my program to take up any system resources until the program it called terminates.


You can do that with fork/exec. You just have to call one of the wait* functions e.g. waitpid(), which will block until the child has terminated.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.