Hello,
When I'm executing an external process using TProcess the command
NumBytes := aProcess.Output.Read((MemStream.Memory + BytesRead)^,READ_BYTES);
waits forever, and this because the external program waits for some input.
How can I force the external application run after 10 sec ?
Please help me. I've searched for a solution for 3 days now.
procedure RunExternalAppInMemo(DosApp:String;AMemo:TMemo);
const
READ_BYTES = 2048;
var
aProcess: TProcess;
MemStream: TMemoryStream;
NumBytes: LongInt;
BytesRead: LongInt;
Lines: TStringList;
begin
// A temp Memorystream is used to buffer the output
MemStream := TMemoryStream.Create;
Lines :=TStringList.Create;
BytesRead := 0;
aProcess := TProcess.Create(nil);
aProcess.CommandLine := DosApp;
aprocess.ShowWindow := swoHIDE;
AProcess.Options := [poNoConsole, poUsePipes, poStderrToOutPut] ;
aProcess.Execute;
AMemo.lines.AddStrings(AProcess.CommandLine);
while (aProcess.Running) do
begin
// make sure we have room
MemStream.SetSize(BytesRead + READ_BYTES);
NumBytes := aProcess.Output.Read((MemStream.Memory + BytesRead)^,READ_BYTES);
if NumBytes > 0 then// All read() calls will block, except the final one.
Inc(BytesRead, NumBytes)
else sleep(100);
end;
MemStream.SetSize(BytesRead);
Lines.LoadFromStream(MemStream);
AMemo.lines.AddStrings(Lines);
aProcess.Free;
Lines.Free;
MemStream.Free;
end;
Thank you