kosta has asked for the wisdom of the Perl Monks concerning the following question:

Hi folks, I am going CRAZY from this, any help MUCH appreciated!!! I have a perl script that creates a tex file.. Now after the tex file is completed I want to convert it it pdf via pdflatex.... So I call:
system "/usr/bin/pdflatex -output-directory /tmp /tmp/perl.tex"; system "mv /tmp/perl.pdf /export/www/html/auth/download/";
Now what happens is that the generated pdf is unreadable (.log file says :
[1{/usr/share/texmf-var/fonts/map/pdftex/updmap/pdftex.map Error: /usr/bin/pdflatex (file /usr/share/texmf-var/fonts/map/pdftex/u +pdmap/pdf tex.map): fflush() failed ==> Fatal error occurred, the output PDF file is not finished!
The funny part is that when I log in via ssh (and even change my user to apache by typing "su apache") then pdflatex works just fine... If I run those two command outside of perl
$ /usr/bin/pdflatex -output-directory /tmp /tmp/perl.tex $ mv /tmp/perl.pdf /export/www/html/auth/download/
=> this works np. Why the heck is perl not able to call the system properly?! Any ideas? Anybody who created pdfs this wat and can help? PLLLLS :)

Replies are listed 'Best First'.
Re: system call to pdflatex
by Corion (Patriarch) on Nov 24, 2011 at 12:05 UTC

    Does your script actually run as the user apache?

    Does the user as which the script runs really have the appropriate permissions? Is something like AppArmor or SELinux active?

    You don't check the result of system - you should do that to be able to stop the process and generate an error message for the user.

Re: system call to pdflatex
by kosta (Sexton) on Nov 24, 2011 at 12:21 UTC
    got it - the whole time I didnt realize (know) that the "system" perl call uses / as its working dir, not the working dir of the perl script... And he obviously didnt have right to write there so... putting cd /tmp && In front of every system call fixed it... took me 3 hours to realize this... GREAT!
      the "system" perl call uses / as its working dir, not the working dir of the perl script
      Not true. Check
      perl -e 'system q{/bin/pwd}'
      Somehow you are setting the script's working directory to /.

        ... it may also be that Apache is launching the Perl script with a working directory of /.