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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
socket1
Forum Commoner
Posts: 82
Joined: Mon Dec 08, 2008 7:40 pm
Location: Shokan, New York

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

Post 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\
Post Reply