Launch Program in C++

Discussion in 'Mac Programming' started by iWill, Feb 25, 2007.

  1. macrumors member

    Joined:
    Nov 24, 2006
    #1
    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?
     
  2. 4np
    macrumors 6502a

    4np

    Joined:
    Feb 23, 2005
    Location:
    The Netherlands
    #2
    I don't know c++ that well but I'm sure there is some 'exec' or 'system' function available?
     
  3. macrumors G3

    iMeowbot

    Joined:
    Aug 30, 2003
    #3
    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
     
  4. thread starter macrumors member

    Joined:
    Nov 24, 2006
    #4
    will this work on any OS?
     
  5. macrumors G3

    iMeowbot

    Joined:
    Aug 30, 2003
    #5
    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.
     
  6. macrumors 6502a

    bbarnhart

    Joined:
    Jan 16, 2002
    Location:
    Stilwell, Kansas
    #6
    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.
     
  7. thread starter macrumors member

    Joined:
    Nov 24, 2006
    #7

Share This Page