Doc #65012 [Nab]: exec command not working from browser
| From: | pganesan at corenttech dot com | Date: | Tue, 11 Jun 2013 13:25:29 +0000 |
| Subject: | Doc #65012 [Nab]: exec command not working from browser | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-9917@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=65012&edit=1
ID: 65012
User updated by: pganesan at corenttech dot com
Reported by: pganesan at corenttech dot com
Summary: exec command not working from browser
Status: Not a bug
Type: Documentation Problem
Package: Apache related
Operating System: WAMP
PHP Version: 5.3.26
Block user comment: N
Private report: N
New Comment:
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
Previous Comments:
------------------------------------------------------------------------
[2013-06-11 13:09:03] 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 12:56:17] 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 12:48:48] 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:47:33] 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 11:47:31] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=65012&edit=1