PHP exec() not returning error message in output

You need to capture the stderr too.

Redirecting stderr to stdout should do the trick. Append 2>&1 to the end of your command.

e.g.

exec("/usr/bin/svn --username something --password something --non-interactive log -r HEAD --xml --verbose http://a51.unfuddle.com/svn/a51_activecollab/ 2>&1", $output);

If it is a complex command (e.g. one with a pipe, like doing a mysqldump and passing it to gzip and then redirecting to file mysqldump ... | gzip > db.sql.gz) create a subshell to capture the overall standard-error and redirect it to standard-output:

exec('( error_command | cat >/dev/null ) 2>&1', $output)
#     ^                                ^   ^
#     `-- sub-shell with the command --ยด   `-- stderr to $output

Leave a Comment