Board index » delphi » CreateProcess & Dos-task

CreateProcess & Dos-task

Hi all,

I want Delphi to launch a dos-task (a ftp-transfer) with
CreateProcess. I want the launching task to wait until the transfer is
complete.

How can I do this?

 

Re:CreateProcess & Dos-task


Michel van Rossum <miche...@xs4all.nl> wrote in article
<55ff8b$...@news.xs4all.nl>...

Quote
> I want Delphi to launch a dos-task (a ftp-transfer) with
> CreateProcess. I want the launching task to wait until the transfer is
> complete.

What DOS program is this?  (Just wondering, I've never seen any DOS
networking/FTP clients.)  

Anyway, just run CreateProcess, and take the handle that's returned and
call WaitForSingleObject API function.  That'll cause your program to wait
until execution of the program is complete.

Re:CreateProcess & Dos-task


Quote
Boris Herman wrote:

> Michel van Rossum wrote:

> > I want Delphi to launch a dos-task (a ftp-transfer) with
> > CreateProcess. I want the launching task to wait until the transfer is
> > complete.

>   Result := CreateProcess(nil,PChar(aCmdLine), nil, nil, False,
>                NORMAL_PRIORITY_CLASS, nil, nil, StartupInfo, ProcessInfo);

Don't forget to:
CloseHandle(ProcessInfo.hProcess);
CloseHandle(ProcessInfo.hThread);

If you don't you'll have (yet another) resource leak in your app.

M.

--
Ettertraktet kaffe, er det ekstra god kaffe?

mailto:martin.lars...@delfi-data.msmail.telemax.no
http://www.delfidata.no/users/~martin

Re:CreateProcess & Dos-task


In article <01bbcacc$c0372840$41233...@InfinityOnline.ionsys.com>,
la...@ionsys.com says...

Quote
> Michel van Rossum <miche...@xs4all.nl> wrote in article
> <55ff8b$...@news.xs4all.nl>...

> > I want Delphi to launch a dos-task (a ftp-transfer) with
> > CreateProcess. I want the launching task to wait until the transfer is
> > complete.

> What DOS program is this?  (Just wondering, I've never seen any DOS
> networking/FTP clients.)  

> Anyway, just run CreateProcess, and take the handle that's returned and
> call WaitForSingleObject API function.  That'll cause your program to wait
> until execution of the program is complete.

I've wanted to do something similar, but I don't want to halt execution
of my app at the WaitForSingleObject call. Is there a way to check the
process has completed in a loop elseware in the app (similar to
GetModuleUsage loops...)

Dustin
dustin_Cr...@us.dell.com

Re:CreateProcess & Dos-task


Quote
>> I want Delphi to launch a dos-task (a ftp-transfer) with
>> CreateProcess. I want the launching task to wait until the transfer is
>> complete.
>What DOS program is this?  (Just wondering, I've never seen any DOS
>networking/FTP clients.)  

Ftp from win95 I guess.

Quote
>Anyway, just run CreateProcess, and take the handle that's returned and
>call WaitForSingleObject API function.  That'll cause your program to wait
>until execution of the program is complete.

I tried that, but in the winapi32 help-file it said that this only
works for gui-applications. However, I'll study it more (and try the
solution Boris gave...)

Re:CreateProcess & Dos-task


Quote
Boris Herman <i...@sight-sound.si> wrote:
>function fileExec(const aCmdLine: String; aHide, aWait: Boolean):
>Hope this helps!

Well, actually it doesn't :(
When I set aHide to false, I notice thatthe dos-box has
"finished choice.com[...]" as a caption. I think this is my problem
now, it won't stop....

(besides that, it works, your routine waits until the dostask
finished, but you have to close it by hand...)

Re:CreateProcess & Dos-task


Dustin Crane <Dustin_Cr...@us.dell.com> wrote in article
<MPG.cf273cf2d389331989...@news.us.dell.com>...

Quote
> In article <01bbcacc$c0372840$41233...@InfinityOnline.ionsys.com>,
> la...@ionsys.com says...
> > Anyway, just run CreateProcess, and take the handle that's returned and
> > call WaitForSingleObject API function.  That'll cause your program to
wait
> > until execution of the program is complete.
> I've wanted to do something similar, but I don't want to halt execution
> of my app at the WaitForSingleObject call. Is there a way to check the
> process has completed in a loop elseware in the app (similar to
> GetModuleUsage loops...)

You have a number of options.

1) Start a thread and WaitForSingleObject in there.

2) Poll the process by using a 0 timeout value -

  if WaitForSingleObject(hProcess,0) = WAIT_OBJECT_0 then
     // process has been signalled - party on!
  else
     // process has not been signalled - twiddle thumbs

3) Use MsgWaitForMultipleObjects - pseudo code something like this:
    REPEAT
      IF MsgWaitForMultipleObjects() determines messages are pending THEN
        Application.ProcessMessages
      ELSE IF process was signalled
        finished := TRUE
      ENDIF
    UNTIL finished or Application.Terminated;
 (One of the messages you process could be WM_QUIT)

I'm sure there are other ways...
--
Tim Knipe
Plasmatech Software Design
E-mail: Plasmat...@nemesis.com.au
Web: http://nemesis.com.au/Plasmatk/index.htm

Other Threads