Re: [Dancer-users] Generating PDF with Template-Plugin-Latex fails inside route handler
Hello,
I want to generate a pdf with Template-Plugin-Latex where the user fills out a html form and the app sends back a pdf.
Outside the route handler create_pdf() works and the pdf is generated, but inside the route handler create_pdf() fails:
latex error - pdflatex exited with errors:
----- Minimal example:
#!/usr/bin/perl use Dancer; use Template::Latex;
sub create_pdf { my $tt = Template::Latex->new({ INCLUDE_PATH => '/path/to/my/app/public/latex', OUTPUT_PATH => '/path/to/my/app/public/pdf', LATEX_FORMAT => 'pdf', });
$tt->process('test.tt', {name => 'Dancer'}, 'test.pdf', binmode => 1) || die $tt->error(); };
# works create_pdf();
get '/' => sub { return 'Hello Dancer'; };
get '/create_pdf' => sub { # works not create_pdf(); };
get '/download/:file' => sub { send_file('/pdf/'.params->{file}); };
dance();
---- My template test.tt
[% USE Latex %] [% FILTER latex('pdf') %] \documentclass[version=last]{scrartcl} \begin{document} Hello [% name %] \end{document} [% END %]
Any suggestions what could be wrong?
Thanks a lot,
Mike _______________________________________________ Dancer-users mailing list Dancer-users@perldancer.org http://www.backup-manager.org/cgi-bin/listinfo/dancer-users
Hello,
I tracked it down a little bit, and found out, that the return code of the system() function is different inside a route handler than outside. Could please someone test this? ------------------------------ #!/usr/bin/perl use Dancer; my $rc = system("/usr/bin/pdflatex -v"); #my $rc = system("/usr/bin/gcc -v"); print "\$rc: $rc\n"; # $rc = 0 get '/system' => sub { $rc = system("/usr/bin/pdflatex -v"); #$rc = system("gcc -v"); '$rc = ' . $rc; # $rc = -1, should be 0 }; dance(); ----------------------------- Thanks, Mike
Mike, The docs for "system" e.g. http://perldoc.perl.org/functions/system.html talk about the return code - and how to interpret it. I've had a play with Dancer using the code as per perldoc "system" - see below. Not sure what the issue is. 1) Run via dancer built in server : perl bin/app.pl http://localhost:3000 shows : Got : [failed to execute: No child processes] 2) Run via plackup : plackup -p 3000 bin/app.pl http://localhost:3000 shows : Got : [child exited with value 0] I expect (2) - and it is what I get on the command line (with the subroutine run_cmd()). Something is different with running via the dancer server - not sure what. Code : #----------------------------------------------------------------------------------- package TestApp; use Dancer ':syntax'; our $VERSION = '0.1'; get '/' => sub { my $o = run_cmd(); return "<p>Got : [$o]</p>"; }; sub run_cmd { my ($return,$msg); system("/usr/local/bin/hg","--version"); $return = $?; if ($? == -1) { $msg = "failed to execute: $!"; } elsif ($? & 127) { $msg = sprintf("child died with signal %d, %s coredump", ($? & 127), ($? & 128) ? 'with' : 'without'); } else { $msg = sprintf("child exited with value %d", $? >> 8); } return $msg; } true; #------------------------------------------------------------------ Cheers, Alastair On 7 January 2011 23:38, Mike Mandel <mandel@stud.fh-hannover.de> wrote:
Hello,
I tracked it down a little bit, and found out, that the return code of the system() function is different inside a route handler than outside. Could please someone test this?
-- Alastair Sherringham http://www.sherringham.net
On 8 January 2011 15:32, Alastair Sherringham <sherringham@gmail.com> wrote:
1) Run via dancer built in server : 2) Run via plackup :
I should add that in both cases I see the correct command output in the server output log, even though I get a wrong return code passed back in (1). -- Alastair Sherringham http://www.sherringham.net
Am 08.01.2011 16:32, schrieb Alastair Sherringham:
Mike,
The docs for "system" e.g.
http://perldoc.perl.org/functions/system.html
talk about the return code - and how to interpret it. I've had a play with Dancer using the code as per perldoc "system" - see below. Not sure what the issue is.
1) Run via dancer built in server :
perl bin/app.pl
http://localhost:3000 shows :
Got : [failed to execute: No child processes]
2) Run via plackup :
plackup -p 3000 bin/app.pl
http://localhost:3000 shows :
Got : [child exited with value 0]
I expect (2) - and it is what I get on the command line (with the subroutine run_cmd()). Something is different with running via the dancer server - not sure what.
Code :
#----------------------------------------------------------------------------------- package TestApp; use Dancer ':syntax';
our $VERSION = '0.1';
get '/' => sub { my $o = run_cmd(); return "<p>Got : [$o]</p>";
};
sub run_cmd { my ($return,$msg); system("/usr/local/bin/hg","--version"); $return = $?;
if ($? == -1) { $msg = "failed to execute: $!"; } elsif ($? & 127) { $msg = sprintf("child died with signal %d, %s coredump", ($? & 127), ($? & 128) ? 'with' : 'without'); } else { $msg = sprintf("child exited with value %d", $? >> 8); } return $msg; }
true; #------------------------------------------------------------------
Cheers, Alastair
On 7 January 2011 23:38, Mike Mandel <mandel@stud.fh-hannover.de> wrote:
Hello,
I tracked it down a little bit, and found out, that the return code of the system() function is different inside a route handler than outside. Could please someone test this?
Hi Alastair, thanks for the hint with plackup. I have tried it and it works now as it should. Thanks, Mike
participants (2)
-
Alastair Sherringham -
Mike Mandel