I want to run an external program and interact with it, but I can't seem to do that with the built-in
TProcess.RunCommandLoop functionality. That's because of this loop in
TProcess.RunCommandLoop:
while Running do
begin
// Only call ReadFromStream if Data from corresponding stream
// is already available, otherwise, on linux, the read call
// is blocking, and thus it is not possible to be sure to handle
// big data amounts bboth on output and stderr pipes. PM.
gotoutput:=ReadInputStream(output,BytesRead,OutputLength,OutputString,1);
// The check for assigned(P.stderr) is mainly here so that
// if we use poStderrToOutput in p.Options, we do not access invalid memory.
gotoutputstderr:=false;
if assigned(stderr) then
gotoutputstderr:=ReadInputStream(StdErr,StdErrBytesRead,StdErrLength,StdErrString,1);
if (porunidle in options) and not gotoutput and not gotoutputstderr and Assigned(FOnRunCommandEvent) Then
FOnRunCommandEvent(self,Nil,RunCommandIdle,'');
end;
Now, I do have
poRunIdle in my options, and have assigned
OnRunCommandEvent to a handler, but specifically due to the checks for
gotoutput and
gotoutputstderr, my handler isn't being called. I know I can subclass
TProcess and override
RunCommandLoop, but is there another way which is simpler?
Also, I see that
TRunCommandEventCode has options
RunCommandReadOutputString and
RunCommandReadOutputStream, but how are these supposed to be used? I see no usages of them in the Lazarus source code.