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?
 

4np

macrumors 6502a
Feb 23, 2005
972
2
The Netherlands
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?
 

iMeowbot

macrumors G3
Aug 30, 2003
8,634
0
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
 

iMeowbot

macrumors G3
Aug 30, 2003
8,634
0
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.
 

bbarnhart

macrumors 6502a
Jan 16, 2002
824
1
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.