Jump to content

PHP4 and the Command Line


ThePsion5

Recommended Posts

Hi guys,I'm attempting to run a PHP script from the windows command line, but for some reason it's just not working...here's my command line script:

php (directories)\test.php file1.txt file2.txt

test.php calls a function that uses the command line arguments like so:

function process($File1=null, $File2=null){  (handle GET, POST, other stuff)  else if($argv[0] != null && $argv[1] != null)  {    $Current = $argv[1];    $Previous = $argv[2];  }}

But whenever I try this, it won't work...according to PHP, the $argc and $argv variables aren't defined. I usually use PHP5 but I'm testing PHP4 compatibility...are command line arguments not supported in PHP4 or is there something else I'm doing wrong? Thanks in advance!

Link to comment
Share on other sites

They are supported. If you are wanting to use the commandline args instead of the function args, try specifying the global versions in the function and see if that makes a difference.function process($File1=null, $File2=null){global $argv, $argc;...Also check in $_SERVER['argv']. You can also do a var_dump($argv) to debug it.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...