External Process ReadOutput stucks lazarus / 31-LCL ---------------------------------------------------------------------- GIOhnny · 2015-04-20 14:44 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. Code: [Select]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 ---------------------------------------------------------------------- Leledumbo · 2015-04-20 16:59 Quote from: GIOhnny on April 20, 2015, 04:44:46 pmand this because the external program waits for some input. ... How can I force the external application run after 10 sec ? if the external program waits for input, shouldn't you be giving the expected input instead of forcing it to run after 10 sec (not really sure with this run after 10 sec, you might mean run for only 10 secs or something else)? ---------------------------------------------------------------------- Basile B. · 2015-04-20 17:13 A little bit more in direction of the previous answer: if the output content is displayed in a memo, then the end-user will able to see that the process expect an input. Maybe you could add an input field so that the user can send what's the process is expecting. If you do so, one important detail: your TProcess must not be a local variable !! ---------------------------------------------------------------------- GIOhnny · 2015-04-20 21:05 So the external command I'm running is : adb -s XXXX install -r "Program.apk" (this command installs the apk directly on the Android device) If the device XXXX was disconnected meanwhile the adb program has the following message and he waits to be reconnected. error: device not found - waiting for device - There is no effective input but the reconnection of the device.  What I need is exactly what Leledumbo said: run for only 10 secs. If no reconnection then kill the process. Thank you ---------------------------------------------------------------------- marcov · 2015-04-21 08:33 You could try to create a TProcess derivative that tries to use reads that timeout after a while, so that control returns. Maybe it can't be done crossplatform, but afaik nobody has tried either, so who knows?