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:
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.Parameters.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(CMD.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