Hugh
Hugh

Reputation: 33

PHP - command line arguments in Windows not being passed

I'm having issues similar to some other people, however I've tried multiple things with no resolution.

I've created a very small, simple test script to show what happens.

<?php
    print "In Script!\n";

    var_dump($argv);

?>

Ok, now i can run it with the following command:-

C:\TEMP>  c:\php\php.exe  hughTest.php 1 2 3 4

Output:-

In Script!
array(4) {
[0]=>
string(12) "hughTest.php"
[1]=>
string(1) "1"
[2]=>
string(1) "2"
[3]=>
string(1) "3"
}

Which is good, this is what I'm expecting. Now just running script as .php:-

C:\TEMP> hughTest.php 1 2 3

Output:-

In Script!
array(1) {
[0]=>
string(20) "C:\temp\hughTest.php"
}

This is NOT what I expected! Where have the parameters gone?

I've checked/tried to modify the file associations with no change in output. I've also tried a few different versions of PHP. (5.4 and 5.5). w32 on x64.

Association: .php = phpfile

ftype: phpfile="C:\php\php.exe" "%1" -- %*

also tried:-

phpfile="C:\php\php.exe" "%1" -- %~2

phpfile="C:\php\php.exe" "%1" %*

phpfile="C:\php\php.exe" "%1" -- "%*"

All with the same results.

Any suggestions on where to look next?

Hugh

Upvotes: 2

Views: 767

Answers (1)

Hugh
Hugh

Reputation: 33

Solution:-

Based off of this:-

@ARGV is empty using ActivePerl in Windows 7

Basically you need to also modify the Windows Registry

[HKEY_CLASSES_ROOT/Applications/php.exe/shell/open/command]
  change the data to something like: "c:\php\php.exe" "%1" %*

[HKEY_CLASSES_ROOT\php_auto_file\shell\open\command]
  change the data to something like: "c:\php\php.exe" "%1" %*

[HKEY_CLASSES_ROOT\phpfile\shell\open\command]
  change the data to something like: "c:\php\php.exe" "%1" %*

Which now results in:-

C:\temp>hughTest.php 1 2 3
In Script!
array(4) {
  [0]=>
  string(20) "C:\temp\hughTest.php"
  [1]=>
  string(1) "1"
  [2]=>
  string(1) "2"
  [3]=>
  string(1) "3"
}


     Hugh

Upvotes: 1

Related Questions