Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

iWill

macrumors member
Original poster
Nov 24, 2006
35
0
So i want to be able from a C++ program to launch another program. I'm sure it's possible (no?) but I've searched all over the internet without success. Can anyone here help me out?
 
So i want to be able from a C++ program to launch another program. I'm sure it's possible (no?) but I've searched all over the internet without success. Can anyone here help me out?

I don't know c++ that well but I'm sure there is some 'exec' or 'system' function available?
 
To create a subprocess: man 2 fork

To replace the subprocess (if you use fork()) or the main process with another program: man 2 execve and man 3 exec

To run a subprocess via the shell (easier, but you get less control and feedback): man 3 system
 
will this work on any OS?

Not necessarily, although there are lots of helper libraries around to help compatibility. fork()/exec() and system() are for Unix-like operating systems.

For windows, you would typically want the spawnl() etc. family of functions, or CreateProcess() and friends.
 
In the Windows world you call CreateProcess(...).

I didn't see read of iMeowbot's answer. I forgot about the run-time library. I'm always using the Win32 API.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.