Thread: Loading a Process

  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    288

    Loading a Process

    Im working on a prog that basically just runs another program and waits for it to end, so far this is what i got:

    Code:
    void LoadProgram(char *sProgramPath)
    {
    	STARTUPINFO startupInfo = {0};
    	PROCESS_INFORMATION processInfo;
    	
    	CreateProcess(NULL, sProgramPath, NULL, NULL, FALSE, 0, NULL, NULL, &startupInfo, &processinfo);
    
    	while (process running = true)
    		Sleep(100);
    
    	CloseHandle(processinfo.hThread);
    	CloseHandle(processinfo.hProcess);
    }
    Thats about all i could figure out, i was wondering, how could i check to see once the process has ended? so for example, i load notepad using the above function, then the function only returns once the user has exited notepad...

    Thanks in advance

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Here is how you would wait for the process to end:

    Code:
    WaitForSingleObject(processinfo.hProcess,INFINITE);
    Call that function right after you create the process, and get rid of that while loop you have.

  3. #3
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    You must provide the size of the STARTUPINFO struct before use.
    Code:
    startupInfo.cb = sizeof(startupInfo);

  4. #4
    Registered User
    Join Date
    Aug 2003
    Posts
    288
    thanks for the quick replies guyz

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. init adopts zombie process?
    By password636 in forum Linux Programming
    Replies: 4
    Last Post: 07-01-2009, 10:05 AM
  2. create a child process that creates a child process
    By cus in forum Linux Programming
    Replies: 9
    Last Post: 01-13-2009, 02:14 PM
  3. Replies: 3
    Last Post: 10-15-2008, 09:24 AM
  4. Problem with forking a process
    By Unitedroad in forum C Programming
    Replies: 10
    Last Post: 10-04-2007, 01:43 AM
  5. process programming
    By St0rM-MaN in forum Linux Programming
    Replies: 2
    Last Post: 09-15-2007, 07:53 AM