Doc #65012 [Nab]: exec command not working from browser
| From: | ab@php.net | Date: | Tue, 11 Jun 2013 13:09:03 +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-9916@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
Updated by: ab@php.net
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:
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);
Previous Comments:
------------------------------------------------------------------------
[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