Doc #65012 [Nab]: exec command not working from browser

From: Date: Tue, 11 Jun 2013 15:24:33 +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-9918@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: 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. Previous Comments: ------------------------------------------------------------------------ [2013-06-11 13:25:29] 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 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 . ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=65012 -- Edit this bug report at https://bugs.php.net/bug.php?id=65012&edit=1

« previous php.doc.bugs (#9918) next »