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

I'm on a Linux machine and I'm coding a Perl script to generate images with text in by calling pbmtextps multiple times. When I try to run pbmtextps in Perl with a system call like this

system("pbmtextps -fontsize 24 SampleText > out.pbm");

I get this error message

pbmtextps: failed to run Ghostscript process: rc=-1

However, if I run the exact same pbmtextps command from the command-line outside of Perl, it runs with no errors.

Why does it cause the ghostscript error when I run it from inside a Perl script?

Also, I tried to hack around this by creating a C program which does the exact same thing with a C system call. That works correctly from the command line. No errors. But then when I try to run that C program from the Perl script with a call to system(), I get the same ghostscript error.

ANSWER: I solved it. The problem was this line in the PERL script:

 $SIG{CHLD} = 'IGNORE';

When I got rid of that (which I need for other things, but not in this script) it worked okay.

Replies are listed 'Best First'.
Re: How to run pbmtextps from inside Perl script
by stefbv (Priest) on Feb 08, 2014 at 18:58 UTC

    I can't reproduce you error, it runs fine from the shell, from a script and with:

    perl -e 'system("pbmtextps -fontsize 24 SampleText > out.pbm")'

    and the 'out.pbm' file is valid.

      Thanks, I eventually figured it out. See ANSWER in original queston.