waitonexit.pp 556 B

123456789101112131415161718192021222324252627282930313233
  1. {$mode objfpc}
  2. uses
  3. process,sysutils;
  4. procedure ExecuteProcess(const Path: string);
  5. var
  6. P: TProcess;
  7. begin
  8. P := TProcess.Create(nil);
  9. try
  10. writeln('Running ',Path);
  11. P.Executable:=Path;
  12. P.Execute;
  13. P.WaitOnExit(1337);
  14. while P.Running do
  15. begin
  16. P.Terminate(255);
  17. Writeln(stderr,'Terminate requested for ',Path);
  18. Sleep(1);
  19. end;
  20. writeln(Path,' returned with exit code: ',P.ExitCode);
  21. finally
  22. P.Free;
  23. end;
  24. end;
  25. begin
  26. ExecuteProcess('./infinity');
  27. ExecuteProcess('./empty');
  28. end.