Thread: calling other programs

  1. #1
    Registered User eth0's Avatar
    Join Date
    Dec 2003
    Posts
    164

    calling other programs

    How do you start another program from within the current running program without the calling program waiting for the return status, as system() does ?

    I would like one program to start another, then the calling program to end leaving the child program running.
    Open source isn't a matter of life or death......
    .......its much more important than that!!


    SuSE Linux - GCC 3.4.2
    XP Pro - Visual Studio 2005 TS, MinGW 3.4.2

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    You could use a threading API and just use the call to system() in a secondary thread.

    edit: I'm sorry - I didn't see the part of your question about ending and leaving the child program running. I'm not sure if the secondary programs execution would halt if you were to shutdown the thread from which it was called.

  3. #3

  4. #4
    Registered User
    Join Date
    Dec 2001
    Posts
    108
    There is avaliable the spawnl function (process.h). Using KERNEL32.DLL CreateProcess will get the job done...

    Code:
    #include <windows.h>
    
    int main(void)
    {
        STARTUPINFO si;
        PROCESS_INFORMATION pi;
    
        GetStartupInfo(& si);
    
        CreateProcess(
            "\\windows\\notepad.exe",
            "notepad",
            0,
            0,
            FALSE,
            NORMAL_PRIORITY_CLASS,
            0,
            0,
            &si,
            &pi
        );
    
       CloseHandle(pi.hProcess);
       CloseHandle(pi.hThread);
    
        return(0);
    }
    Notepad will be left in process while the calling application's process terminates.
    Last edited by DarkStar; 02-22-2005 at 09:30 PM.
    rwalt

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Communication between programs?
    By johny145 in forum Windows Programming
    Replies: 3
    Last Post: 06-01-2005, 10:14 PM
  2. Problem using java programs within C code
    By lemania in forum Linux Programming
    Replies: 1
    Last Post: 05-08-2005, 02:02 AM
  3. calling functions within functions
    By edd1986 in forum C Programming
    Replies: 3
    Last Post: 03-29-2005, 03:35 AM
  4. POSIX/DOS programs?
    By nickname_changed in forum C++ Programming
    Replies: 1
    Last Post: 02-28-2003, 05:42 AM
  5. Altering The Program's Executable?
    By Aidman in forum C++ Programming
    Replies: 7
    Last Post: 12-31-2002, 05:11 AM