Board index   FAQ   Search  
Register  Login
Board index PHP PHP Installation

PHP command line interface ignores my arguments

Forum for you who has PHP installation issues

Moderators: macek, egami, gesf

PHP command line interface ignores my arguments

Postby doraemon » Mon Aug 22, 2011 5:44 am

Hello!

I'm new to this forum. I didn't find anything useful by using search...

I have installes Windows 7 CLI php (5.2). I associated .php with php itself, and
I have defined a PATHEXT for .php so that .php is not necessary to run a script.
Now it runs (apparently) fine, I mean echo echoes something. But I cannot get arguments.
Here are the program and its output.
1. The script:
-----8<----------8<----------8<----------8<----------8<----------8<-----
<?php
echo "Program arguments:\n";
echo "Argc = " . $argc . "\n";
print_r($argv);
?>
-----8<----------8<----------8<----------8<----------8<----------8<-----

2. A test and its output:
-----8<----------8<----------8<----------8<----------8<----------8<-----
C:\Users\Dora\PHPTest\ScripTest 1 2 3 4 5
Program arguments:
Argc = 1
Array
<
[0] => C:\Users\Dora\PHPTest\ScripTest.php
>
-----8<----------8<----------8<----------8<----------8<----------8<-----

That's it. I would expect argc to be 6 and the array to have 6 elements.

By the way, I am using Windows 7 ultimate 64 bits.

Any hint?

Thanks,

Dora.
doraemon
New php-forum User
New php-forum User
 
Posts: 4
Joined: Mon Aug 22, 2011 5:27 am

Re: PHP command line interface ignores my arguments

Postby egami » Mon Aug 22, 2011 6:03 am

argc = count of arguments
argv = value of arguments in an array

Code: Select all

<?

var_dump
($argv);

echo 
"-------------\r\n";

var_dump($argc);

echo 
"-------------\r\n";

?>



[mybox@tools phpnet]$ php index.php one two three 4

array(5) {
[0]=>
string(9) "index.php"
[1]=>
string(3) "one"
[2]=>
string(3) "two"
[3]=>
string(5) "three"
[4]=>
string(1) "4"
}
-------------
int(5)
-------------
User avatar
egami
php-forum GURU
php-forum GURU
 
Posts: 2197
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: PHP command line interface ignores my arguments

Postby egami » Mon Aug 22, 2011 6:06 am

I don't know much about Windows. Personally, I think Windows has a place in the gaming world, and Office Manipulation, but has no place in the server world. (Except Microsoft Exchange).

But if it's anything like the Unix side of the house,
#!c:/path/to/php.exe

should be the first line.
User avatar
egami
php-forum GURU
php-forum GURU
 
Posts: 2197
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: PHP command line interface ignores my arguments

Postby doraemon » Mon Aug 22, 2011 3:34 pm

Hello!
Thanks for your reply. Unfortunately, it does not solve my problem.
I copied your script in an editor, added php after the <? (otherwise it doesn't work
at all) and saved it as ScriptTest2.php.
When I run it, the output is now:

C:\Users\Dora\PHPTest\ScripTest2 one two three 4
array(1) {
[0]=>
string(36) "C:\Users\Dora\PHPTest\ScripTest2.php"
}
-------------
int(1)
-------------

Thanks anyway.

Dora

egami wrote:argc = count of arguments
argv = value of arguments in an array

Code: Select all

<?

var_dump
($argv);

echo "-------------\r\n";

var_dump($argc);

echo "-------------\r\n";

?>



[mybox@tools phpnet]$ php index.php one two three 4

array(5) {
[0]=>
string(9) "index.php"
[1]=>
string(3) "one"
[2]=>
string(3) "two"
[3]=>
string(5) "three"
[4]=>
string(1) "4"
}
-------------
int(5)
-------------
doraemon
New php-forum User
New php-forum User
 
Posts: 4
Joined: Mon Aug 22, 2011 5:27 am

Re: PHP command line interface ignores my arguments

Postby doraemon » Mon Aug 22, 2011 3:43 pm

Hello again!

egami wrote:I don't know much about Windows. Personally, I think Windows has a place in the gaming world, and Office Manipulation, but has no place in the server world. (Except Microsoft Exchange).

But if it's anything like the Unix side of the house,
#!c:/path/to/php.exe

should be the first line.


My intention is not to use it in a server, but as a command line interface.
Windows has its place in gaming an office, but it has also (unfortunately or fortunately depending
on user taste) its place in hardware development. That's what I do. And my purpose is to
generate c++ code.
I could use ActivePerl which works fine, but I prefer PHP and I recently I discovered the command
line interface which works extremely well on MacOS and Linux.

That's about it...

Dora.
doraemon
New php-forum User
New php-forum User
 
Posts: 4
Joined: Mon Aug 22, 2011 5:27 am

Re: PHP command line interface ignores my arguments

Postby egami » Tue Aug 23, 2011 6:53 am

Dora,
In the UNIX environment, there are two types of PHP installs. One in CGI mode (regular web) and one in CLI mode. Essentially, they call the same file, but in a different way. In the Windows world, it might be the same way.

A while ago, Nullsig posted a website that had an auto installer which installed the CGI/CLI & WAMP stuffs together, perhaps do a google search on that?
User avatar
egami
php-forum GURU
php-forum GURU
 
Posts: 2197
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: PHP command line interface ignores my arguments

Postby doraemon » Tue Aug 23, 2011 3:23 pm

Hello Egami,

Thanks for your reply.
I think I used the right installer. One proof of this is that I can write a php script
that works on the command line, except that it does not accept the arguments.
The example I posted earlier shows the output. The script can echo something
(therefore the install seems to be correct) but its only problem is that it does not
accept arguments and always shows argc as 1 whatever arguments I give to it.

I'm going to look for nullsig anyway.

Thanks,

Pascal
doraemon
New php-forum User
New php-forum User
 
Posts: 4
Joined: Mon Aug 22, 2011 5:27 am


Return to PHP Installation

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.