[Lazarus] TProcess pipe through StdIn

Michael Van Canneyt michael at freepascal.org
Sat Aug 18 11:33:24 CEST 2012



On Fri, 17 Aug 2012, Leonardo M. Ramé wrote:

> I'm using xhtml2pdf to convert html text to pdf. If I use from the
> command line, I can do this:
>
> cat /var/www/cgi-bin/salida.html | xhtml2pdf - -
>
> or this:
>
> xhtml2pdf - - < /var/www/cgi-bin/salida.html
>
> The parameters "- -" mean, take input from StdIn and send output to
> StdOut.
>
> When I try to execute the same using TProcess, it apparently never
> receives the input.
>
> Here's a modified snippet I copied from http://wiki.freepascal.org/Executing_External_Programs
>
> procedure TForm1.Button1Click(Sender: TObject);
> var
>  lProcess: TProcess;
>  lStr: TStringList;
>  lText: string;
>
> begin
>  lProcess := TProcess.Create(nil);
>  lStr := TStringList.Create;
>  try
>    lStr.LoadFromFile('/var/www/cgi-bin/salida.html');
>    lProcess.Options := [poUsePipes, poStderrToOutPut];
>    lProcess.CommandLine := '/usr/bin/xhtml2pdf - -';
>    lProcess.Execute;
>    lText := lStr.Text;
>    lProcess.Input.Write(lText[1], Length(lText));

You should probably close the input. xhtml2pdf has no way of knowing it received all input.

Michael.


More information about the Lazarus mailing list