Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: perl wkhtmltopdf Error: Unable to write to destination

by RichardK (Priest)
on May 07, 2014 at 16:25 UTC ( #1085340=note: print w/ replies, xml ) Need Help??


in reply to perl wkhtmltopdf Error: Unable to write to destination

'|-' means open a command and pipe data to it, & the help for open says :-

You are not allowed to "open" to a command that pipes both in and out, + but see IPC::Open2, IPC::Open3,...

So it's no great surprise that it doesn't work.


Comment on Re: perl wkhtmltopdf Error: Unable to write to destination
Download Code
Re^2: perl wkhtmltopdf Error: Unable to write to destination
by djlerman (Acolyte) on May 07, 2014 at 18:22 UTC

    Thank you for your response.

    I will try it with IPC::Open3.

    I'm trying to create a simple example for IPC::Open3. Should I create a separate post relating to getting Open3 to work?

    Below is code I am trying and here is the output I get:

    OUTPUT:
    err-> /bin/ls: write error: Bad file descriptor retval-> 512
    CODE:
    #!/usr/bin/perl use warnings; use strict; use IPC::Open3; print "Content-type: text/html\n\n"; print ' <!DOCTYPE HTML> <html lang="en"> <head> <title>IPC::Open3 Example</title> </head> <body>'; my $cmd = '/bin/ls -la'; my $pid = open3(\*WRITER, \*READER, \*ERROR, $cmd); while( my $output = <READER> ) { print "output-> $output\n"; } while(my $errout = <ERROR> ) { print "err-> $errout\n"; } waitpid($pid, 0 ) or die "$!\n"; my $retval = $?; print "retval-> $retval\n"; print " </body> </html>";

      Here is the final working solution I came up with. If there is anything I missed please let me know. I don't know if I am using "gensym()" correctly. The main thing that was an issue was rights on the server side.

      #!/usr/bin/perl use warnings; use strict; use IPC::Open3; use Symbol; my $cmd = '/usr/local/bin/wkhtmltopdf - -'; my $err = gensym(); my $in = gensym(); my $out = gensym(); my $pdf = ''; my $pid = open3($in, $out, $err, $cmd) or die "could not run cmd : $c +md : $!\n"; my $string = '<html><head></head><body>Hello World!!!<br /><br /><br / +> IMG: <img id="image" src="data:image/gif;base64,R0lGODlhFwAPAKEAAP///w +AAAMzMzLi3tywAAAAAFwAPAAACQIyPqQjtD98RIVpJ66g3hgEYDdVhjThyXSA4aLq2rgp +78hxlyY0/ICAIBhu/HrEEKIZUyk4R1Sz9RFEkaIHNFgAAOw==" /> </body></html>'; print $in $string; close($in); while( <$out> ) { $pdf .= $_ } # for trouble shooting while( <$err> ) { # print "err-> $_<br />\n"; } # for trouble shooting waitpid($pid, 0 ) or die "$!\n"; my $retval = $?; # print "retval-> $retval<br />\n"; print "Content-Disposition: attachment; filename='testPDF.pdf'\n"; print "Content-type: application/octet-stream\n\n"; print $pdf;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1085340]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2014-09-19 23:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (151 votes), past polls