php shell_exec return null

Masoud Nazari picture Masoud Nazari · Jan 6, 2016 · Viewed 7.9k times · Source

I want run php ../cat1/index.php gr_s2/3/gr-n40 1200 command by php. The shell_exec return NULL as result but when I try that command on cmd, output was shown correctly.

What happen in php and shell_exec ?!

Note: The command with different parameters (Like: php ../cat1/index.php gr_s2/3/gr-n40 800) works correctly in both (php and cmd).

Answer

shozdeh picture shozdeh · Jan 6, 2016

There is a note in php manual page of shell_execute:

Note: This function can return NULL both when an error occurs or the program produces no output. It is not possible to detect execution failures using this function. exec() should be used when access to the program exit code is required.

Source: http://php.net/manual/en/function.shell-exec.php

So your code running with error. Try with exec. If you want, insert your code (or blocks) to be checked.