0

I am running Symfony and Ghostscript and I cannot get shell_exec to execute the script.

Simple test to make sure shell_exec() works inside of Symfony: it works, I can see the directory structure

$output = shell_exec('ls') and output the results ... 

From terminal: it works and it creates the PDF file

/usr/local/bin/gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=/file/path/file-c.pdf -dBATCH /file/path/file-a.pdf /file/path/file-b.pdf ... 

From inside of Symfony: it does not work

$output = shell_exec('/usr/local/bin/gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=/file/path/file-c.pdf -dBATCH /file/path/file-a.pdf /file/path/file-b.pdf');

If I output the results print_r($output), I just get the following but file-c.pdf is not created...

GPL Ghostscript 9.23 (2018-03-21) Copyright (C) 2018 Artifex Software, Inc. All rights reserved. This software comes with NO WARRANTY: see the file PUBLIC for details.

If I do a "which gs" I get the following:

/usr/local/bin/gs

What could I be doing wrong in this example?

Why would it work from the terminal but fail in the shell_exec()? I can run other commands from shell_exec() and they work fine.

yivi
  • 42,438
  • 18
  • 116
  • 138
LargeTuna
  • 2,694
  • 7
  • 46
  • 92
  • That seems like Ghostscript completed normally with no errors. It does not appear to be failing. My guess would be the file is not being created where you expect. Possiby because the application is running as a different user. What happens in your initial 'ls' example if you pipe the output of ls to a file ? Eg ls > /file/path/ls.txt – KenS Nov 23 '19 at 09:27
  • I just realised you're (I think) only capturing stdout, you need to capture stderr as well and output that to a file, it may tell you more. – KenS Nov 23 '19 at 10:43

0 Answers0