Page 1 of 1

shell_exec not returning any errors?

Posted: Tue Jul 18, 2006 3:40 am
by zany_cynic8
Hi everyone..I'm fairly new to PHP and I'm stuck with this problem..I have this snippet of code that won't work as expected

Code: Select all

$db_host = "localhost";
$db_port = "3306";
$db_name = "myDatabase";
$db_dump = "db.sql"
$result = shell_exec("mysqldump --host=$db_host --port=$db_port --opt $db_name > $db_dump &2>1");
This does work however when I pass in a false $db_name it should generate an error but it doesn't
It seems like shell_exec is not getting the error message from mysql

I have tried to e.g.
echo shell_exec("error command");
and is giving me an error..

what's wrong with shell_exec not retrieving error message when used mysqldump command??

Posted: Tue Jul 18, 2006 3:42 am
by jamiel
As far as I am aware shell_exec only returns output that goes to STDOUT. mysqldump is probably returning it's error to STDERR.

Posted: Tue Jul 18, 2006 4:06 am
by zany_cynic8
add '2>&1' to the end of your shell command to have STDERR returned as well as STDOUT.
from http://au2.php.net/manual/en/function.s ... .php#28994

any other suggestions on how I can get the error messages? thanks

Posted: Tue Jul 18, 2006 4:07 am
by jamiel
You are redirecting all output to $db_dump. Your error is probably being redirected there aswell because you have redirected STDERR to STDOUT.

Posted: Tue Jul 18, 2006 4:28 am
by zany_cynic8
I'm not getting it.. Do you have any ideas on how I could get the error message form mysql? please please help..thanks

Posted: Tue Jul 18, 2006 4:44 am
by jamiel
Don't redirect STDERR to STDOUT and then read the latest comment at http://php.net/shell_exec

You want to tweak that function to return $stderr

Posted: Tue Jul 18, 2006 7:56 pm
by zany_cynic8
thanks for the help..I followed your advice and now it's working fine...