View Full Version : Launch Program in C++
iWill
Feb 25, 2007, 07:37 AM
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
Feb 25, 2007, 07:46 AM
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
Feb 25, 2007, 07:48 AM
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
iWill
Feb 25, 2007, 08:02 AM
will this work on any OS?
iMeowbot
Feb 25, 2007, 08:10 AM
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
Feb 25, 2007, 08:21 AM
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.
iWill
Feb 25, 2007, 08:22 AM
FINALLY!!Found a great website.
In case other people have the same fustrating problem as i do here's the site:
http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1044654269&id=1043284392
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.