Page 1 of 1

Problems with the full path of a command in exec()

Posted: Sun Apr 19, 2009 4:01 pm
by socket1
I have these two commands in PHP

Code: Select all

exec($MYSQL_BIN_DIR.'mysqldump.exe --user='.$MYSQL_USER.' --password='.$MYSQL_PASS.' '.$db['Database'].' > "'.$BackupDir.'build\\SQL\\'.$db['Database'].'.sql"');
//echoed its this:
// C:\MySQL\bin\mysqldump.exe --user=root --password=stuff123 testing > "C:\_Backups\build\SQL\testing.sql"
 
exec('"'.$MYSQL_BIN_DIR.'mysqldump.exe" --user='.$MYSQL_USER.' --password='.$MYSQL_PASS.' '.$db['Database'].' > "'.$BackupDir.'build\\SQL\\'.$db['Database'].'.sql"');
//echoed its this: 
// "C:\MySQL\bin\mysqldump.exe" --user=root --password=stuff123 testing > "C:\_Backups\build\SQL\testing.sql"
The first one.. works in PHP and works also when I copy the echoed output and paste it into the server's CMD window.
The second one doesn't work in PHP but when I copy the echoed output and paste it into the server's CMD window it works.

I am trying to put quotes around the paths since if there is a space in the path to the MySQL directory the command will fail.
Assuming $MYSQL_BIN_DIR is something like C:\Program Files\MySQL\bin\