Sign in Join

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

Mailing lists / lazarus / 2012-08

TProcess pipe through StdIn

4 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

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

Leonardo M. Ramé

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));
    lStr.Clear;
    lStr.LoadFromStream(lProcess.Output);
    lStr.SaveToFile('output.pdf');
  finally
    lStr.Free;
    lProcess.Free;
  end;
end;

Reply by email

Michael Van Canneyt
to Leonardo M. Ramé: I'm using xhtml2pdf to convert html text to pdf. If I use from the command line, I can do…
Leonardo M. Ram? wrote 33 lines
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.

Reply by email