[fpc-devel] Running programs with output redirection

Graeme Geldenhuys graemeg.lists at gmail.com
Sat Jul 16 22:18:04 CEST 2011


On 16 July 2011 22:37, Hans-Peter Diettrich <DrDiettrich1 at aol.com> wrote:
>
> Does there exist a simple way to run "diff", and to redirect its output into
> an file? A batch file? Platform independence would be nice, of course.

Execute diff with the two parameters via TProcess. Read the output as
normal, and simply write that output to a text file using TFileStream,
TStringList etc..

eg:
  p := TProcess.Create(nil);
  p.Options := [poUsePipes, poStdErrToOutPut];
  ....
  p.Execute
  ...
    SetLength(Buf,BufSize);
    repeat
      if (p.Output<>nil) then
      begin
        Count:=p.Output.Read(Buf[1],Length(Buf));
        // add Buf to a TFileStream, TStringList etc.
      ...
     until Count=0;


-- 
Regards,
  - Graeme -


_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://fpgui.sourceforge.net



More information about the fpc-devel mailing list