Board index » delphi » How to launch a .bat file and wait until then end of it ?

How to launch a .bat file and wait until then end of it ?

Everything in is the title.

I have ga a Dos batch file
( for example
- login xxxxx
- copy z:*.dat c:\mydatadir
- logout)

and I need to launch this file from Delphi under Windows NT
(with ShellExecute or something else) and I have to wait that
 the last command is completed before starting anything else in
my Delphi application.
Any idea ?

Thanks for your help.

Bruno ETIENNE

 

Re:How to launch a .bat file and wait until then end of it ?


Quote
In article <4ooo4c$...@dub-news-svc-3.compuserve.com> <beaCons...@msn.com> writes:
>From: <beaCons...@msn.com>
>Subject: How to launch a .bat file and wait until then end of it ?
>Date: 1 Jun 1996 06:31:40 GMT
>Everything in is the title.
>I have ga a Dos batch file
>( for example
>- login xxxxx
>- copy z:*.dat c:\mydatadir
>- logout)
>and I need to launch this file from Delphi under Windows NT
>(with ShellExecute or something else) and I have to wait that
> the last command is completed before starting anything else in
>my Delphi application.
>Any idea ?
>Thanks for your help.

Use shellexec or winexec
eg

Procedure mywinexec(progname : string; SHOWMODE : integer);
Var
   winerr : integer;
   estr : pchar;
   done : boolean;

begin
   estr := stralloc(255);
   strpcopy(estr, progname);
   winerr := winexec(estr, SHOWMODE);
   if (winerr < 32) then case winerr of
0 :     showmessage('System was out of memory, executable file was corrupt, or relocations were invalid.');
{and so on}
           end
           else begin
             repeat
               application.processmessages;
               done := application.terminated or (getmoduleUsage(winerr) = 0);
             until done;
           end;
   strdispose(estr);
end;

Re:How to launch a .bat file and wait until then end of it ?


Quote
beaCons...@msn.com wrote:

> Everything in is the title.

> I have ga a Dos batch file
> ( for example
> - login xxxxx
> - copy z:*.dat c:\mydatadir
> - logout)

> and I need to launch this file from Delphi under Windows NT
> (with ShellExecute or something else) and I have to wait that
>  the last command is completed before starting anything else in
> my Delphi application.
> Any idea ?

> Thanks for your help.

> Bruno ETIENNE

Check out CreateProcess API to start the bat file.  
Check out WaitForSingleObject API to wait for it to finish before continuing execution.

Other Threads