🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.nativeapi
3 messages
3 total messages Started by Phuoc Sun, 23 Sep 2007 13:58
How to run a Command in a progam and wait until finish?
#1347
Author: Phuoc
Date: Sun, 23 Sep 2007 13:58
16 lines
1185 bytes
I tried to google "ShellExecute wait" there are many different solutions  
suggested. They all look a bit complicated. Is there another command for  
this and can pause the main process?

thanks
Phuoc

-- 
===============================
I'm using BCB5 on XP Home
Re: How to run a Command in a progam and wait until finish?
#1248
Author: Michel Leunen
Date: Sun, 23 Sep 2007 19:04
32 lines
1934 bytes
Phuoc wrote:
> I tried to google "ShellExecute wait" there are many different solutions 
> suggested. They all look a bit complicated. Is there another command for 
> this and can pause the main process?

Don't use ShellExecute() for this but CreateProcess() along with 
WaitForSingleObject().
Something like this:

    PROCESS_INFORMATION piProcInfo;
    STARTUPINFO siStartInfo;

    memset(&siStartInfo, NULL, sizeof(STARTUPINFO));
    siStartInfo.cb = sizeof(STARTUPINFO);
    //launch your application
    CreateProcess(NULL, "yourApp.exe",
                  NULL, NULL, 0, 0, NULL, NULL,
                  &siStartInfo, &piProcInfo);

    //Wait for your application to end
    WaitForSingleObject(piProcInfo.hProcess,INFINITE);
    ...

HTH
Michel

-- 
----------------------------------------
Michel Leunen
http://www.leunen.com/

----------------------------------------
Re: How to run a Command in a progam and wait until finish?
#1249
Author: Bob Gonder
Date: Sun, 23 Sep 2007 21:13
15 lines
1521 bytes
Michel Leunen wrote:

>    CreateProcess(NULL, "yourApp.exe",
>                  NULL, NULL, 0, 0, NULL, NULL,
>                  &siStartInfo, &piProcInfo);
>
>    //Wait for your application to end
>    WaitForSingleObject(piProcInfo.hProcess,INFINITE);

	CloseHandle(  piProcInfo.hProcess );
	CloseHandle(  piProcInfo.hThread );

Yes, that is the prefered method.
Also available are the C spawn functions spawnl, spawnp, etc.
 spawnl( P_WAIT, filename, filename)
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads