3

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 :(

5
  • When you test in the shell, are you the same user (www-data)? The web server might be chroot'd to a specific directory for security reasons. Commented Jan 31, 2013 at 18:04
  • Is safe_mode enabled? This limits the directories that exec() can run commands from. Commented Jan 31, 2013 at 18:05
  • @nickb nice point, in the shell I run as 'ubuntu', I'm gonna check this out! Commented Jan 31, 2013 at 18:08
  • @Barmar I've checked safe_mode using phpinfo() and it is disabled (set to Off) Commented Jan 31, 2013 at 18:10
  • Ok so I've tested in my shell using sudo -su www-data and it worked. By the way the script to be executed by Casper is located, and operated in a directory whose tree is owned (group) by www-data Commented Jan 31, 2013 at 18:20

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Ok, I've found the answer using your tip! CasperJS being based on PhantomJS, it needs a X server so I can't run the command on a web server (however, I think there is a minimal/headless mode, and headless X server, so I'll check this out)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.