代码之家  ›  专栏  ›  技术社区  ›  Ivan Prodanov

如何并行执行PostBuild事件上的程序?

  •  2
  • Ivan Prodanov  · 技术社区  · 16 年前

    我成功地将编译器设置为在项目选项中使用以下指令生成/运行项目时执行另一个程序:

    call program.exe param1 param2
    

    问题是编译器执行“program.exe”并等待它终止,然后运行项目可执行文件。

    我要问的是:如何设置编译器并行运行两个可执行文件,而不等待PostBuild事件中的一个文件终止?

    提前谢谢

    3 回复  |  直到 16 年前
        1
  •  2
  •   Sertac Akyuz    16 年前

    我不知道IDE是如何等待由“start”启动的进程终止的,但是在您自己的程序启动程序中以最简单的方式调用“CreateProcess”似乎是有用的。

    编辑某物;

    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.
    

    然后在后期制作中:

    "X:\...\starter.exe" "X:\...\program.exe" param1 param2
    
        2
  •  0
  •   Alan Clark    16 年前

    不要调用program.exe,而是使用start program.exe

        3
  •  0
  •   da-soft    16 年前

    创建一个bat文件。按照Alan的建议,在start中输入几个命令:

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