views:

257

answers:

3

I managed to set the compiler to execute another program when the project is built/ran with the following directive in project options:

call program.exe param1 param2

The problem is that the compiler executes "program.exe" and waits for it to terminate and THEN the project executable is ran.

What I ask: How to set the compiler to run both executables in parallel without waiting for the one in PostBuild event to terminate?

Thanks in advance

A: 

Instead of call program.exe, use start program.exe

Alan Clark
The same happens.
John
A: 

Create a bat file. Put there few commands with start, as Alan suggested:

start program.exe param1 param2
start program.exe param1 param2
start program.exe param1 param2 
start program.exe param1 param2

Then call this bat file.

da-soft
Still the same.I tried both 'call' and 'start' on the batfile.
John
+1  A: 

I'd have no clue how the IDE manages to wait for the termination of processes initiated by "start", but calling "CreateProcess" at its simplest in your own program starter seems to serve.

Compile sth. like;

program starter;

{$APPTYPE CONSOLE}

uses
  sysutils, windows;

var
  i: Integer;
  CmdLine: string;
  StartInfo: TStartupInfo;
  ProcInfo: TProcessInformation;
begin
  try
    if ParamCount > 0 then begin
      CmdLine := '';
      for i := 1 to ParamCount do
        CmdLine := CmdLine + ParamStr(i) + ' ';
      ZeroMemory(@StartInfo, SizeOf(StartInfo));
      StartInfo.cb := SizeOf(StartInfo);
      ZeroMemory(@ProcInfo, SizeOf(ProcInfo));
      if not CreateProcess(nil, PChar(CmdLine), nil, nil, False,
                      NORMAL_PRIORITY_CLASS, nil, nil, StartInfo, ProcInfo) then
        raise Exception.Create(Format('Failed to run: %s'#13#10'Error: %s'#13#10,
                            [CmdLine, SysErrorMessage(GetLastError)]));
    end;
  except
    on E:Exception do begin
      Writeln(E.ClassName + ', ' +  E.Message);
      Writeln('... [Enter] to dismiss ...');
      Readln(Input);
    end;
  end;
end.

and then on PostBuild put:

"X:\...\starter.exe" "X:\...\program.exe" param1 param2
Sertac Akyuz
Exactly the method I did,but a bit different.I accept your answer even problem was solved already. :-)
John