|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2013-06-11 11:47 UTC] pganesan at corenttech dot com
Description:
------------
trying to database dump using following Query using exec command,
exec('pg_dump -U postgres -h localhost -p 5432 recipedb1 > C:\TEMP\dumpfilename1.sql');
exec('C:\Program Files\PostgreSQL\9.0\bin\pg_dump -U postgres -h localhost -p 5432 recipedb1 > C:\TEMP\dumpfilename1.sql');
But Its working fine from running in terminal(cli mode),
Please check
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Nov 03 16:00:02 2025 UTC |
Basically it works like this exec('c:\\windows\\system32\cmd.exe /C "c:\\my\\commando.exe --arg"'); All the backslashes have to be escaped. Also you'll need to use escapeshellarg() if you pass something dynamically or if there are spaces in the path. Also it's better to put the suffix as well, like command.exe .I tried with this ,Its not working, can you please check my code and guide me exec('c:\\windows\\system32\cmd.exe /C "C:\\Program Files\\PostgreSQL\\9.0\\bin\\pg_dump.exe -U postgres -h localhost -p 5432 recipedb1 > C:\\TEMP\\new.sql"');You have to shellescapearg() the path to 'program files', something like this works perfectly $cmd = escapeshellarg('c:\\Program Files\\7-Zip\\7z.exe'); exec("c:\\windows\\system32\\cmd.exe /C \"$cmd -h\"", $out); print_r($out);I tried with $cmd = escapeshellarg('pg_dump -U postgres -h localhost -p 5432 recipedb1 > C:\TEMP\dump123s.sql'); exec("c:\\windows\\system32\\cmd.exe /C \"$cmd -h\"", $out); print_r($out); and $cmd = escapeshellarg('pg_dump -U postgres -h localhost -p 5432 recipedb1 > C:\TEMP\dump123s.sql'); exec("c:\\windows\\system32\\cmd.exe /C \"$cmd -h\"", $out); print_r($out); and $cmd = escapeshellarg('C:\\Program Files\\PostgreSQL\\9.0\\bin\\pg_dump.exe'); exec("c:\\windows\\system32\\cmd.exe /C \"$cmd -U postgres -h localhost -p 5432 recipedb1 > C:\\TEMP\\new.sql\"", $out); print_r($out); But there is no output, empty file is created, But database dump is not exported, Also I delete the file, Its says cannot delete file, Its used by cmd.exe