I can see the result of:
echo exec("whoami"); // will output "www-data"
however if I try to run a real world command:
echo exec("casperjs myscript.js /foo/bar");
then nothing happens:
- no output (the casperjs script should output some stdout log messages)
- no action (the script should create an image, using an absolute path, but it doesn’t)
- no errors from PHP
- no output of the shell command
I’ve searched on StackOverflow, and went to try alternative ways (tested first in the shell, to be sure they work):
echo exec("casperjs /absolute/path/to/myscript.js");
echo exec("/usr/local/bin/casperjs /absolute/path/to/myscript.js");
I tested also other combinations, using system(), shell_exec() and even passthru()
but it’s always the same thing: no error, no output, even in php log files, so it is very, very hard to understand the problem 🙁
Try
echo exec("casperjs myscript.js /foo/bar 2>&1");to redirect stderr to stdout which wouldn’t otherwise show.It could be an error in your cmdline or maybe casperjs is not in your $PATH, etc.