works now ! was: bypass shell - pipe into child pid and receive otput
- From: Mirco Wahab <wahab-mail@xxxxxx>
- Date: Tue, 13 Feb 2007 00:23:24 +0100
Sherm Pendley wrote:
xhoster@xxxxxxxxx writes:Mirco Wahab <wahab-mail@xxxxxx> wrote:
print $chld_in $ht;You may have a buffering/deadlock problem here, assuming $prog starts
close $chld_in;
my $pdf; do { local $/; $pdf = <$chld_out> };
producing output before it completely reads its input.
I'm not certain that's a valid assumption in this case. The job of this
program is to take HTML input and produce PDF output. I don't think it
could do that without first reading all of its input. One can, for example,
include an inline style attribute on the very last p element in the HTML
body, that positions it at the top of the rendered page.
Thank you all for your valuable help. I stripped down the program
to the problem and solved it somehow with the help and input from
this group.
1) the program used is the 'open source' htmldoc 1.9
(http://www.htmldoc.org/software.php)
2) it works(!) as intended (IPC::open2, no shell) via '-'
in old fashioned 'cgi-Mode' but *NOT* under mod-perl!
(I didn't consider this one)
The following is now a perfectly working program:
<cat /cgi-bin/convert.pl>
#!/usr/bin/perl
use strict;
use warnings;
use IPC::Open2;
my $html = q{<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head><body><h1>PDF it is!</h1>
<p style="height:400px;width:400px;border:blue 1px solid;overflow:hidden;">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nam sodales, mauris
et consequat condimentum, nisi enim rhoncus nulla, a vulputate arcu ligula non
tortor. Praesent sem. </p></body></html>
};
print "Content-type: application/pdf\n\n"; # print "Content-type: text/html\n\n";
select(STDOUT); $| = 1; # don't buffer
$ENV{HTMLDOC_NOCGI} = 1; # used _as_a_program_ *from* a cgi
my $prog = '/usr/bin/htmldoc';
my @args = qw'--webpage --quiet -t pdf14 -';
my ($chld_out, $chld_in, $childpid);
$childpid = open2($chld_out, $chld_in, $prog, @args)
or die "can't open pipe to $prog: $!";
print $chld_in $html;
close $chld_in;
my $pdf; do { local $/; $pdf = <$chld_out> };
close $chld_out;
waitpid $childpid, 0;
print $pdf;
</>
In my trials before - it bailed because of the mod_perl
environment (I guess), something the program didn't like
(don't really know what).
In the end, the program is a nice solution for
on-the-fly generation of pdf.
Thanks to all people involved (Anno, Ilya, Uri, Xho)
Regards
Mirco
.
- Follow-Ups:
- References:
- bypass shell - pipe into child pid and receive otput
- From: Mirco Wahab
- Re: bypass shell - pipe into child pid and receive otput
- From: Sherm Pendley
- Re: bypass shell - pipe into child pid and receive otput
- From: Mirco Wahab
- Re: bypass shell - pipe into child pid and receive otput
- From: xhoster
- Re: bypass shell - pipe into child pid and receive otput
- From: Sherm Pendley
- bypass shell - pipe into child pid and receive otput
- Prev by Date: Re: handling STDIN line by line in Gtk
- Next by Date: Re: bypass shell - pipe into child pid and receive otput
- Previous by thread: Re: bypass shell - pipe into child pid and receive otput
- Next by thread: Re: works now ! was: bypass shell - pipe into child pid and receive otput
- Index(es):
Relevant Pages
|