
Hmm chess engine, nice idea. I'll try to help a little bit:
// st:=P.Output.ReadAnsiString; <- this is my try
It will *not* work, because it was meant to be used after
WriteAnsiString had been used. To be more accurate, it reads 4 bytes
size of string from the stream prior to reading the string itself. Of course in your case the chess engine is not going to write the 4 bytes for
size of string!!
Solution, maybe:
if P.Output.NumBytesAvailable>0 then
begin
SetLength(st, P.Output.NumBytesAvailable);
P.Output.ReadBuffer(st[1], P.Output.NumBytesAvailable);
end;
// so after second command how to catch different output
Again, read
NumBytesAvailable using
ReadBuffer. That's the new output.
NumBytesAvailable holds the number of bytes that you did NOT read yet.
Sleep(1000); // <- is this neccessary?
I tend to believe that the answer depends on the application you are running, chess engine here, so I don't know. If it did not work, just give it enough time to write its response before you hit it with another request!
I expected it to work, while using
nslookup but it proved me wrong. And in general according to
TProcess docs:
Note that writing to the stream may cause the calling process to be suspended when the created process is not reading from it's input, ...
Maybe someone with better knowledge can give us more.
stL.LoadFromStream(P.Output);
stL.SaveToFile('AjDaVidime.txt'); // nothing stores particular
It should work, but maybe data was not ready. stL.
LoadFromStream(P.Output) internally calls P.Output.
Read which is implemented. Do check:
if P.Output.NumBytesAvailable>0 then
before your call
LoadFromStream,
ReadBuffer, or
ReadYou might want to know about
TAsyncProcess in unit
AsyncProcess, it has an event that fires when data is available.