use strict; use IPC::Run qw(start finish pump);
sub handler
{
my $r = shift;
my $html = qw
{
<html>
<body>
<h1>Foo</h1>
Bar<br>
Baz
</body>
</html>
};
# command
my $cmd = [ "/path/to/htmldoc",
qw(
--quiet --jpeg --webpage -t pdf
--bodyfont Helvetica --fontsize 7
--browserwidth 1024
--left 16 --top 16 --right 16 --bottom 16
--header ... --footer ...
-
)];
# run htmldoc subprocess
my $output;
my $handle = start( $cmd, \$html, \$output, ) || die "Unable to open htmldoc: $?";
pump $handle while( length $html );
finish $handle;
# set the filename
$fname =~ s/ /_/g;
$lname =~ s/ /_/g;
# read pdf back in and send to browser
#print header( -content_type => "application/pdf",
print header( -content_type => "application/pdf",
-content_disposition => qq{attachment; filename="foo.pdf"} );
print $output;
}
Alejandro Galue wrote:
Hello All,
I´m using mod_perl2 and Apache2 over Fedora Core 1.
I have a handler that need to call an external program to complete the request.
This program put its output to a file, and then I read this output from the handler (after system function) to complete the request.
My problem is (I assume) when I call system, it returns inmediatly and of course when I try to read the file output, it does not exist; becase it was created later.
How can I force to wait for a system function terminate the execution of an external program.
Thanks, Alejandro Galue.
-- Report problems: http://perl.apache.org/bugs/ Mail list info: http://perl.apache.org/maillist/modperl.html List etiquette: http://perl.apache.org/maillist/email-etiquette.html