Running the following script in PHP 5.5.4 CLI on Win7 32bit
php -r "print_r($argv);" 1 2 3 4 5 6 7 8 9 10 11 12 13 14
I can see that only 8 arguments are actually parsed:
Array
(
[0] => -
[1] => 1
[2] => 2
[3] => 3
[4] => 4
[5] => 5
[6] => 6
[7] => 7
)
Does Windows or PHP limit the number of command line args to 8/ total 9?
Update:
Works as expected on same PC with PHP 5.5.7 -> so at least on Win7 this is a PHP-specific problem.
The behaviour changes depending on if the script is run from the php folder or if php is found via path. A procmon
trace seems to indicate that the problem is with Windows as- even before the PHP.exe image is being loaded- a different number of parameters is passed:
php.exe Process Start SUCCESS Parent PID: 9088, Command line: "\Program Files\php\php" -r "print_r($argv);" 1 2 3 4 5 6 7, Current directory: C:\
php.exe Process Start SUCCESS Parent PID: 9088, Command line: "\program files\php\php" -r "print_r($argv);" 1 2 3 4 5 6 7 8 9 10 11 12 13 14, Current directory: C:\
php.exe Process Start SUCCESS Parent PID: 9088, Command line: php -r "print_r($argv);" 1 2 3 4 5 6 7 8 9 10 11 12 13 14, Current directory: C:\Program Files\php\
All parameters only seem to be available if PHP is NOT taken from the path.
Kind of, on some Windows environments. To get more than 9 parameters on Windows XP you need to "shift" the parameters in your batch file.
I can't find any reference to this command on versions above XP, so it may be that this issue goes away with later versions of Windows.
A comment on PHP.NET covers it here: http://www.php.net/manual/en/features.commandline.php#56846
To pass more than 9 arguments to your php-script on Windows, you can use the 'shift'-command in a batch file. After using 'shift', %1 becomes %0, %2 becomes %1 and so on - so you can fetch argument 10 etc.
Here's an example - hopefully ready-to-use - batch file:
foo.bat:
@echo off
:init_arg
set args=
:get_arg
shift
if "%0"=="" goto :finish_arg
set args=%args% %0 goto :get_arg
:finish_arg
set php=C:\path\to\php.exe
set ini=C:\path\to\php.ini
%php% -c %ini%
foo.php %args%
Usage on commandline: foo -1 -2 -3 -4 -5 -6 -7 -8 -9 -foo -bar
A print_r($argv) will give you all of the passed arguments.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With