TProcess input lazarus / 32-Linux ---------------------------------------------------------------------- HomeBoy38 · 2022-12-23 09:51 Hi, I am trying to interface a command line program (so no console shown) but I am stuck on the input part. Here is the simplified version of my code: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TMainForm.BCONClick(Sender: TObject);var AStringList: TStringList; MyOutput: String; CMD: TProcess;begin CMD := TProcess.Create(nil); CMD.Options := [poUsePipes, poStderrToOutPut, poWaitOnExit]; CMD.Executable := 'myexe'; CMD.Parameters.Clear; CMD.Pa rameters.Add('param1'); CMD.Parameters.Add('param2'); MyOutput := 'yes' + #10; CMD.Execute; CMD.Input.Write(MyOutput, Length(MyOutput)); AStringList := TStringList.Create; MyOutput := '';  sleep(100); Application.ProcessMessages; AStringList.LoadFromStream(CM D.Output); MyOutput := AStringList.Strings[AStringList.Count - 1]; if Copy(MyOutput, 1, 3) = 'err' then  ShowMessage('error'); CMD.Free; AStringList.Free;end;  While running, 'myexe' can ask for one or more 'yes' to continue, so far, I am trying to input at least the first one. If an error occurs, I am correctly exiting the 'myexe' and the error message is shown (if everything goes fine, nothing to do). I really do not understand how to catch the 'Type yes' message from 'myexe', but even more, I do not understand why blindly writing to the input does not work? Thanks in advance ---------------------------------------------------------------------- marcov · 2022-12-23 11:22 Have a look at  https://stackoverflow.com/questions/72335247/input- and-output-pipe-in-lazarus-tprocess and the ZIP that I posted there.  Note that it is best to first test with some simple FPC programs before testing your final target, just in case that program somehow behaves atypically. Note that your code says to wait on exit (Powaitonexit), and only then sends input. ---------------------------------------------------------------------- Edson · 2022-12-23 15:49 To interact with a process I recommend to use my library: https://github.com/t-edson/UnTerminal It's completely driven by events and have prompt detection so you can answer any question the program ask. ---------------------------------------------------------------------- HomeBoy38 · 2022-12-26 08:26 Hi, First thanks to both of you for your answers. If I understand correctly, I cannot use TProcess natively to do what I need without wrapping TProcess. I will make a try on your advices. During my researches, I have found your codes, once appeared a bit complex for my simple search, and the other one was talking about Minecraft server so I wrongly thought I was leaving my path. Thanks. ---------------------------------------------------------------------- Hartmut · 2022-12-26 11:19 For 'TProcess' with redirected input and output I use this code. Works on Windows and Linux. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure exec_TProcess_InOut(cmd: ansistring; SLK,SLI: TStringList;                            var SLO: TStringList; var ec,es: longint);   {calls an external program 'cmd' via 'TProcess' and redirects Input from    StringList 'SLI' and redirects Output into StringList 'SLO'. Waits until    the external program has finished.     - 'SLK' = commandline parameters.     - 'ec' and 'es' are error codes.     - 'SLO': must be initialized external}   var PZ: TProcess;       s: ansistring;       n,i: longint;   begin   ec:=-1; es:=-1; {unspecific error codes, e.g. if 'cmd' not found}   PZ:=TProcess.Create(nil);    try     try       PZ.Executable:=cmd;       PZ.Parameters:=SLK;       PZ.Options:=[poUsePipes];       PZ.Execute;        n:=SLI.Count;     for i:=0 to n-1 do          begin          s:=SLI.Strings[i] + LineEnding;           PZ.Input.Write(s[1],length(s));          end;      while PZ.Running do {wait until external program has finished}        sleep(50);        SLO.LoadFromStream(PZ.Output);      finally     ec:=PZ.ExitCode;       es:=PZ.ExitStatus;       PZ.Free;     end; {try2}    except     on E:Exception do        begin        if ec=0 then ec:=-1;        if es=0 then es:=-1;        end;   end; {try1}   end; procedure Test_TProcess_InOut;   {Demo for exec_TProcess_InOut()}   var SLK,SLI,SLO: TStringList;       cmd: ansistring;       ec,es: longint;   begin   cmd:='my.exe';   SLK:=TStringList.Create; {commandline parameters: }      SLK.Add('param1');      SLK.Add('param2');   SLI:=TStringList.Create; {create Input-StringList}      SLI.Add('username');      SLI.Add('password');      SLI.Add('y');   SLO:=TStringList.Create; {create Output-StringList}    exec_TProcess_InOut(cmd,SLK,SLI,SLO, ec,es);   SLK.Free;   SLI.Free;   SLO.Free;    if (ec<>0) or (es<>0) then writeln('ERROR: ec=', ec, ' es=', es);   end; HTP ---------------------------------------------------------------------- HomeBoy38 · 2022-12-26 18:27 @marcov: I was not able to input to myexe using your sample code, I did not figure out why and I quit @Edson: this is too complex for my need by I am sure it will help someone else @Hartmut: your code is very similar to my tests before I post my question, but yours works  Thanks for your contribution, on my side, it appears to be closed, but if anyone else needs, you can use my topic Have a great end of year