|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2002-07-11 22:44 UTC] php dot hc at saustrup dot 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 :-)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 15:00:01 2025 UTC |
FYI: PHP uses popen(), not execve().. In 4.2.1 there is pcntl_exec() which behaves similarly to the system execve. Maybe that's what you want to use..? Try these scripts: shell_args_1arg.php: <?php echo exec('./test.sh "213 123"'); ?> shell_args_2arg.php: <?php echo exec('./test.sh 213 123'); ?> test.sh: <----8<----> #!/bin/sh echo $1 <----8<---->