Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2007-05

Question about TProcess

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Darius Blaszijk

The following piece of code is giving me headaches. When I add the option poUsePipes, the application starts and does not seem to do anything else anymore. It just opens a commandline terminal and that is that. When I leave the option out the application actually starts "make" and then crashes because AProcess.Output is nil.
What did I forget? I'm working on WinXP. On Linux btw the code works.

Darius

procedure ExecuteApp(CmdLine: string);
var
  AProcess: TProcess;
  AStringList: TStringList;
begin
  AProcess := TProcess.Create(nil);
  AStringList := TStringList.Create;
  AProcess.CommandLine := CmdLine;
  AProcess.Options := AProcess.Options + [poWaitOnExit, poUsePipes];
  AProcess.Execute;
  AStringList.LoadFromStream(AProcess.Output);
  AStringList.SaveToFile('output.txt');
  AStringList.Free;
  AProcess.Free;
end;
begin
  ExecuteApp('make');
end.

Reply by email

Vincent Snijders
to Darius Blaszijk
Darius Blaszijk wrote 28 lines
The following piece of code is giving me headaches. When I add the option poUsePipes, the application starts and does not seem to do anything else anymore. It just opens a commandline terminal and that is that. When I leave the option out the application actually starts "make" and then crashes because AProcess.Output is nil. What did I forget? I'm working on WinXP. On Linux btw the code works. Darius procedure ExecuteApp(CmdLine: string); var AProcess: TProcess; AStringList: TStringList; begin AProcess := TProcess.Create(nil); AStringList := TStringList.Create; AProcess.CommandLine := CmdLine; AProcess.Options := AProcess.Options + [poWaitOnExit, poUsePipes]; AProcess.Execute; AStringList.LoadFromStream(AProcess.Output); AStringList.SaveToFile('output.txt'); AStringList.Free; AProcess.Free; end; begin ExecuteApp('make'); end.

Maybe the output buffer is full and the application is waiting for you to read from the pipe. See the reading large output program at http://wiki.lazarus.freepascal.org/Executing_External_Programs#Reading_large_output

Vincent

Reply by email

Darius Blaszijk
to Vincent Snijders

Thanks Vincent,

I did not think of it as there are only about 30lines of output. It works now.

Darius

Vincent Snijders wrote 41 lines
Darius Blaszijk schreef: > The following piece of code is giving me headaches. When I add the > option poUsePipes, the application starts and does not seem to do > anything else anymore. It just opens a commandline terminal and that > is that. When I leave the option out the application actually starts > "make" and then crashes because AProcess.Output is nil. > What did I forget? I'm working on WinXP. On Linux btw the code works. > > Darius > > procedure ExecuteApp(CmdLine: string); > var > AProcess: TProcess; > AStringList: TStringList; > begin > AProcess := TProcess.Create(nil); > AStringList := TStringList.Create; > AProcess.CommandLine := CmdLine; > AProcess.Options := AProcess.Options + [poWaitOnExit, poUsePipes]; > AProcess.Execute; > AStringList.LoadFromStream(AProcess.Output); > AStringList.SaveToFile('output.txt'); > AStringList.Free; > AProcess.Free; > end; > > begin > ExecuteApp('make'); > end. Maybe the output buffer is full and the application is waiting for you to read from the pipe. See the reading large output program at http://wiki.lazarus.freepascal.org/Executing_External_Programs#Reading_large_output Vincent _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email