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

发布于 2024-08-27 11:57:01 字数 222 浏览 9 评论 0原文

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

call program.exe param1 param2

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

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

提前致谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

静谧 2024-09-03 11:57:01

我不知道 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.

然后在 PostBuild 上输入:

"X:\...\starter.exe" "X:\...\program.exe" param1 param2

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
北渚 2024-09-03 11:57:01

使用启动program.exe,而不是调用program.exe

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

再浓的妆也掩不了殇 2024-09-03 11:57:01

创建一个bat文件。按照 Alan 的建议,在其中添加一些带启动的命令:

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

然后调用此 bat 文件。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文