Bug #18291 Updated: exec() arguments (+suggested solution)
ID: 18291
Updated by: sniper@php.net
Reported By: php.hc@saustrup.net
-Status: Open
+Status: Bogus
Bug Type: Program Execution
Operating System: RedHat Linux 7.3
PHP Version: 4.1.2
New Comment:
Not any bug. It's up to the external program how
it handles the arguments you pass it..try same on the cmd line and
you'll understand what I mean. To get "'s through, you need to escape
them..
Check this out:
http://www.php.net/manual/en/function.escapeshellarg.php
exec() doesn't split anything, it passes what is given to it
straight to the shell to be executed as is.
Previous Comments:
------------------------------------------------------------------------
[2002-07-11 22:44:08] php.hc@saustrup.net
This kept me up all night :-) I needed to pass a textstring to an
external program, and did something like this in PHP:
exec('/usr/bin/binary 1 2 3 "a b c" 4 5 6');
It kept screwing up, and after debugging it I realized that the exec()
function actually called /usr/bin/binary with 9 arguments, and not 7 as
I thought it would. Apparently PHP's exec() just splits up the string
where it finds whitespaces and thinks they're different arguments. I'm
not sure about the proper solution, but it would be awesome with a more
"strict" exec()-like function that could work something like this:
newexec('/usr/bin/binary',array('1','2','3','a b
c','4','5','6'));
That way, there would be NO doubt about the arguments :-)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=18291&edit=1
Thread (10 messages)