Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^2: perl wkhtmltopdf Error: Unable to write to destination

by djlerman (Sexton)
on May 07, 2014 at 18:22 UTC ( [id://1085354]=note: print w/replies, xml ) Need Help??


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

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>";

Replies are listed 'Best First'.
Re^3: perl wkhtmltopdf Error: Unable to write to destination
by djlerman (Sexton) on May 09, 2014 at 18:25 UTC

    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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1085354]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2024-07-22 07:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.