Board index » delphi » Executing a batch file

Executing a batch file

I am using Delphi 5 Pro and wish to execute a batch file from a button on a
form. The batch file calls a series of Turbo Pascal programs compile on TP
Version 7 (DOS) and I have tried in vain to re-write and compile them in
Delphi, hence the need to run the old batch file.
Can anyone suggest sample code to do this as the published examples in books
will not compile.
Many thanks
Rod Nicholls
ran...@aol.com
Rod
 

Re:Executing a batch file


Use the following function to execute the batch file, wait for it to finish
and return the exit code.

function RunAndWait(const FileName: String): DWORD;
var
  StartupInfo: TStartupInfo;
  ProcessInfo: TProcessInformation;
begin
  Result := STILL_ACTIVE;
  GetStartupInfo(StartupInfo);
  if not CreateProcess(nil, PChar(FileName), nil, nil, IsConsole,
    NORMAL_PRIORITY_CLASS, nil, nil, StartupInfo, ProcessInfo) then
    RaiseLastWin32Error;
  try
    if WaitForSingleObject(ProcessInfo.hProcess, INFINITE) = WAIT_OBJECT_0
then
      GetExitCodeProcess(ProcessInfo.hProcess, Result);
  finally
    CloseHandle(ProcessInfo.hThread);
    CloseHandle(ProcessInfo.hProcess);
  end;
end;

Quote
"Rod Nicholls" <ran...@aol.com> wrote in message

news:20010821023003.01608.00000631@mb-ck.aol.com...
Quote
> I am using Delphi 5 Pro and wish to execute a batch file from a button on
a
> form. The batch file calls a series of Turbo Pascal programs compile on TP
> Version 7 (DOS) and I have tried in vain to re-write and compile them in
> Delphi, hence the need to run the old batch file.
> Can anyone suggest sample code to do this as the published examples in
books
> will not compile.
> Many thanks
> Rod Nicholls
> ran...@aol.com
> Rod

Re:Executing a batch file


check out ShellExecute

Quote
"Rod Nicholls" <ran...@aol.com> wrote in message

news:20010821023003.01608.00000631@mb-ck.aol.com...
Quote
> I am using Delphi 5 Pro and wish to execute a batch file from a button on
a
> form. The batch file calls a series of Turbo Pascal programs compile on TP
> Version 7 (DOS) and I have tried in vain to re-write and compile them in
> Delphi, hence the need to run the old batch file.
> Can anyone suggest sample code to do this as the published examples in
books
> will not compile.
> Many thanks
> Rod Nicholls
> ran...@aol.com
> Rod

Re:Executing a batch file


Thanks for your help, the example code did the trick and I will try
ShellExecute
Many thanks
Rod Nicholls
ran...@aol.com
Rod

Other Threads