|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
commandline + Linux
I can not get working php correctly from the command line under Linux.
php install(php version 4.2.1): 1.configure --enable-cli 2.make 3.make install I tested with the following script(cline.php): #!/usr/local/bin/php // my php file is under /usr/local/bin <?php if ($argc == 2) echo "1 argument"; else echo "no arguments"; ?> Now my problem is that it always outputs : "no arguments" even if run like this: php cline.php firstarg <?php $a=5; $b=3; echo $a+$b; ?> The above script echos out 8, so the php file is processed=> I think, I have got a problem with those argc,argv things. I also looked in the php.ini file the line: register_argc_argv = On (i thinks its good). Under windows, i can run these scipts with php-cli.exe(and both of them works), but under Linux there is no php-cli. I hope you can understand my problem(explained with my poor english), and I hope someone got the solution. |
|
#2
|
|||
|
|||
|
RE: commandline + Linux
hmmm ...
I use php cli, however I never passed my cli scripts any arguments. FYI: those argv and argc things those are "Argument Vector" and "Argument Count", respectively. From looking at your code, I would say it works as designed! You are checking if argc (argument count) is equal to two and you are calling your script with "php cline.php firstarg" which has an argc of one! Unless there is some funky way on how php calculates argc, your script works as designed. HTH |
|
#3
|
|||
|
|||
|
RE: commandline + Linux
php cline.php firstarg - in this call argc=2
Copied from the php manual: $argc and $argv. The first is the number of arguments plus one (the name of the script running). The second is an array containing the arguments, starting with the script name as number zero ($argv[0]). Anyway I've got a half solution. I turned on notices and get a notice : undefined variable argc Then I turned register_globals=On and I got the script working.I think there must be a better way, because under windows it runs perfectly with register_globals=Off. |
![]() |
| Viewing: Codewalkers Forums > PHP Related > PHP Installation > commandline + Linux |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|