Reputation: 35
Im trying to execute the node command from PHP with this function:
$output = shell_exec('node -v');
echo $output; // null
and it returns me null instead of version. Why it's not working? Node.js is installed on the server and working when executing from shell.
Upvotes: 0
Views: 694
Reputation: 5513
The documentation for the shell_exec function says
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.
Its possible that node -v
dosn't output to stdout or that another error is occurring. Could you maybe try another program such as uptime
, its also worth noting it won't work if your PHP is running in safe_mode
.
Upvotes: 1