Bug #18291 Updated: exec() arguments (+suggested solution)

From: Date: Fri, 12 Jul 2002 04:21:29 +0000
Subject: Bug #18291 Updated: exec() arguments (+suggested solution)
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-13903@lists.php.net to get a copy of this message
 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)

« previous php.bugs (#13903) next »