Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: perl wkhtmltopdf Error: Unable to write to destination

by RichardK (Parson)
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.

Replies are listed 'Best First'.
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:

    err-> /bin/ls: write error: Bad file descriptor retval-> 512
    #!/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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1085340]
[atcroft]: stevieb: Sad to say that I only recently learned that particular trick, but I have since found it very useful.... :)
[james28909]: ill be back with a solution eventually
[stevieb]: it's a reminder to re-inforce it :P
[atcroft]: james28909: That particular questions was a bit of trick, actually (depending on the country you are in). More interesting is, if you are trying to subtract from an epoch time, for instance, you might have to consider when/if DST occurs for a location,
[atcroft]: because you may have to adjust the number of seconds you change from an epoch from 86400 (not to mention leap seconds)....
[atcroft]: james28909: Although if your program is using a database, you might be able to "pass the buck" to the database and ask it to do the date change for you....

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2017-04-29 04:37 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (531 votes). Check out past polls.