fpc/packages/fcl-process/examples/waitonexit.pp
2016-01-24 13:55:51 +00:00

34 lines
556 B
ObjectPascal

{$mode objfpc}
uses
process,sysutils;
procedure ExecuteProcess(const Path: string);
var
P: TProcess;
begin
P := TProcess.Create(nil);
try
writeln('Running ',Path);
P.Executable:=Path;
P.Execute;
P.WaitOnExit(1337);
while P.Running do
begin
P.Terminate(255);
Writeln(stderr,'Terminate requested for ',Path);
Sleep(1);
end;
writeln(Path,' returned with exit code: ',P.ExitCode);
finally
P.Free;
end;
end;
begin
ExecuteProcess('./infinity');
ExecuteProcess('./empty');
end.