The output from the program will not be large. Leledumbo also suggested
- removing poWaitOnExit
- using while AProcess.Running do
but before that I would like to have a simple input working.
I have added a simple input to Hello.exe:
program Hello;
var
TheirName:string;
begin
writeln('Hello');;
Writeln('What is your name?');
Readln(TheirName);
Writeln('Your Name is ',TheirName);end.
There is no final readln for the reason given above.
I have modified my Lazarus procedure with:
procedure TForm1.Button1Click(Sender: TObject);
begin
AStringList:=TStringList.Create;
AProcess := TProcess.create(nil);
AProcess.Commandline :='Hello.exe';
AProcess.Options:=AProcess.Options+[poWaitOnExit, poUsePipes];
AProcess.Execute;
AStringList.LoadFromStream(AProcess.Output);
AStringList.SaveToFile('output.txt');
BStringList:=TStringList.Create;
BStringList.Add('Fred');
BStringList.SaveToStream(AProcess.Input); AStringList.Free;
BStringList.Free;
AProcess.Free;
end;
It all looks logical to me. I will repeat the lines that catch the output stream and have the whole program captured.
HOWEVER: The program compiles but when it runs it stops on
BStringList.SaveToStream(AProcess.Input);and complains of a stream write error.
Any suggestions?[/list]