PHP shell_exec() Behaves Differently Than Terminal Command Line MacOS

361 Views Asked by At

Scanline is a simple command line utility used for scanning documents from a twain scanner. http://blog.scottkleper.com/scanline-command-line-scanner-for-mac/

I am trying to use Scanline through a PHP script using shell_exec(); the same way that I would use it directly from the terminal in MacOS.

When I run Scanline directly from the command line, it detects all the attached scanners and prints them out ./scanline -list

When I run Scanline using shell_exec(), it does not detect any devices.

So far, I have changed the apache user to my local user, and have added the local user to the sudoers file. If I run 'whoami' in shell_exec() it is the same result as if I run it in command line.

I have printed the environment using printenv in command line, and have setup all of the same variables in my php script before executing shell_exec() using putenv(); If I run shell_exec('printenv 2>&1'), it is the exact same environment as when I run printenv in command line.

All the permissions are correct and allow access, and scanline runs when executed through shell_exec() without error (I checked apache's error logs, as well as put a error_reporting(E_ALL); in the top of the PHP file to printout any issues along the way). The only difference in how the program is executed is that in command line the devices are detected, and run through shell_exec(), no devices are found.

Any ideas as to what else I could be missing between command line and using shell_exec() ?

I also tried using system(), exec(), and shell_exec() interchangeably with the same result.

0

There are 0 best solutions below