如何使用 pascal 在执行两个外部程序之间设置延迟/睡眠?

dai*_*ini 1 freepascal lazarus

我有这样的代码:

begin
    RunProgram:=TProcess.Create(nil);
    RunProgram.Commandline:='calc.exe';
    RunProgram.Execute;
    RunProgram.Commandline:='notepad.exe';
    RunProgram.Execute;
    RunProgram.Free;
end.
Run Code Online (Sandbox Code Playgroud)

我想在执行 calc.exe 后休眠或延迟

Ken*_*ite 5

你的想法是对的——就是Sleep

begin
  RunProgram:=TProcess.Create(nil);
  RunProgram.Commandline:='calc.exe';
  RunProgram.Execute;
  Sleep(1000);             // Adds a 1 second delay
  RunProgram.Commandline:='notepad.exe';
  RunProgram.Execute;
  RunProgram.Free;
end.
Run Code Online (Sandbox Code Playgroud)

您可能需要将Windows单位(或者可能是不同的单位 - 我不熟悉 FreePascal 的单位排列)添加到您的uses子句中才能编译该Sleep函数。