php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #65012 exec command not working from browser
Submitted: 2013-06-11 11:47 UTC Modified: 2013-06-11 15:24 UTC
From: pganesan at corenttech dot com Assigned:
Status: Not a bug Package: Apache related
PHP Version: 5.3.26 OS: WAMP
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: pganesan at corenttech dot com
New email:
PHP Version: OS:

 

 [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


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-06-11 12:47 UTC] ab@php.net
-Status: Open +Status: Feedback
 [2013-06-11 12:47 UTC] ab@php.net
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 .
 [2013-06-11 12:48 UTC] ab@php.net
-Status: Feedback +Status: Not a bug
 [2013-06-11 12:48 UTC] ab@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

and actually it's not a bug :)
 [2013-06-11 12:56 UTC] pganesan at corenttech dot com
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"');
 [2013-06-11 13:09 UTC] ab@php.net
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);
 [2013-06-11 13:25 UTC] pganesan at corenttech dot com
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
 [2013-06-11 15:24 UTC] ab@php.net
Of course the out is empty as it's redirected to a file. I'd remove the stdout 
redirection and see what the out is, that would bring you forward. But please, use 
the support channel, this bugtracker is really for the PHP bugs.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 27 04:01:29 2024 UTC