argv and stdin

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

w3cynic
Forum Newbie
Posts: 12
Joined: Sun Aug 11, 2002 11:06 am

argv and stdin

Post by w3cynic »

The only way I can pass $vars to PHP from a shell is by appending them as a GET request eg;

Code: Select all

./script.phpx "&var=true"
Reading arguments from the command line or stdin just doesn't work. register_argc_argv=On in my .ini and I've also tried setting register_globals to On with no success.

Does anybody have any ideas?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

try the command line version of php
(php-cli.exe on win32)
w3cynic
Forum Newbie
Posts: 12
Joined: Sun Aug 11, 2002 11:06 am

Well

Post by w3cynic »

I'm using PHP 4.2.2 compiled as a standalone CGI, and I'm not running on win32. I think there will be some improvements for running scripts from the shell in 4.3, however I'm having enough problems without compiling an alpha version.

Thanks for the reply - any other ideas?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

php-cli.exe is part of the php-distribution - at least within the .zip-version.
I (i.e.) have no other php-executable ;)

edit: sorry, once again I read a post only half :( !! NOT win32 !! :oops:
so, which OS is it?
w3cynic
Forum Newbie
Posts: 12
Joined: Sun Aug 11, 2002 11:06 am

Post by w3cynic »

This is on linux.

I think I'll try re-compiling with --enable-cli and see if that fixes it
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

it should do
my gentoo-emerge of php works nice with this option
w3cynic
Forum Newbie
Posts: 12
Joined: Sun Aug 11, 2002 11:06 am

It's not working

Post by w3cynic »

I've always compiled as a module before and have never had any errors. Here is part of the output of a make test.

Code: Select all

Trivial "Hello World" test                                           ... passed
ї1mSimple POST Method test (002.phpt)                                   ... failedїm
ї1mGET and POST Method combined (003.phpt)                              ... failedїm
ї1mTwo variables in POST data (004.phpt)                                ... failedїm
ї1mThree variables in POST data (005.phpt)                              ... failedїm
Add 3 variables together and print result                            ... passed
Multiply 3 variables and print result                                ... passed
Divide 3 variables and print result                                  ... passed
Subtract 3 variables and print result                                ... passed
Testing | and & operators                                            ... passed
ї1mTesting $argc and $argv handling (011.phpt)                          ... failedїm
I'm going to try building the alpha/beta of 4.3
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

hmmm 4.3-dev...features sound nice but
I think I keep on 4.2.x for a while ;)
w3cynic
Forum Newbie
Posts: 12
Joined: Sun Aug 11, 2002 11:06 am

make test for 4.3.0 alpha2

Post by w3cynic »

Here are the make test == FAIL for 4.3.0 alpha2 on my system.

Code: Select all

======================
PHP_SAPI    : cli
PHP_VERSION : 4.3.0-dev
PHP_OS      : Linux
======================
FAIL Test array_merge and array_walk (001.phpt)
FAIL Test arsort, asort, krsort, ksort, rsort, and sort (002.phpt)
FAIL Test usort, uksort and uasort (003.phpt)
-------------------------------
PASS Trivial "Hello World" test (001.phpt)
SKIP Simple POST Method test (002.phpt)
SKIP GET and POST Method combined (003.phpt)
SKIP Two variables in POST data (004.phpt)
SKIP Three variables in POST data (005.phpt)
PASS Add 3 variables together and print result (006.phpt)
PASS Multiply 3 variables and print result (007.phpt)
PASS Divide 3 variables and print result (008.phpt)
PASS Subtract 3 variables and print result (009.phpt)
PASS Testing | and & operators (010.phpt)
FAIL Testing $argc and $argv handling (011.phpt)
---------------------------------
FAIL Output buffering tests (006.phpt)
FAIL Regression test (023.phpt)
FAIL Looped regression test (may take a while) (024.phpt)
FAIL Internal hash position bug on assignment (Bug #16227) (031.phpt)
Really I want sockets, curl and gd support so a packaged version is not suitable. I don't understand why these tests are failing :(
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

ok, I'm trying within a chroot-jail :D
just a (or two to a hundred) moment(s)
w3cynic
Forum Newbie
Posts: 12
Joined: Sun Aug 11, 2002 11:06 am

good idea...

Post by w3cynic »

...but I'm running the tests straight after ./configure --without-installing. I'm not running the thing in a chroot env.

I think that I must be missing a library or something, I just don't know which one
:roll:
This could be a good reason to try that gentoo distro everybody keeps talking about. Thanks anyway.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

hmmm...I get almost the same errors :(
with and without chroot
w3cynic
Forum Newbie
Posts: 12
Joined: Sun Aug 11, 2002 11:06 am

ughhhh

Post by w3cynic »

Well I just did a make install on 4.3.0 to see if I could pass a variables via $_GET from the command line, as I could with 4.2.2 - no ball.

Are you getting 'almost the same errors' as me - or just with/without chrooting.

anyway gentoo dl is at 35% I should have it installed pretty soon 8)
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Are you getting 'almost the same errors' as me - or just with/without chrooting.
both ;)
anyway gentoo dl is at 35% I should have it installed pretty soon
it depends.
if you took stage3-tarball: may be.
If you're starting with stage1 only your journey has just begun.
Somewhere in the documentation the author states "X will take for ever to compile. KDE even longer." He's right :D
But it's worth the time. Although I don't use KDE anymore (too colourous, too slow, too - too - fancy ;) ) I'm impressed what my K6 can do 8)
daemorhedron
Forum Commoner
Posts: 52
Joined: Tue Jul 23, 2002 11:03 am

Post by daemorhedron »

getting back to the original question, I am on linux with php 4.2.2, and this worked for me :

** CLITEST.PHP **

#!/usr/local/bin/php -f
<?php
print_r($_SERVER['argv']);
?>

[daemorhedron@obsidian daemorhedron]$ ./clitest.php h f s
Array
(
[0] => ./clitest.php
[1] => h
[2] => f
[3] => s

The only thing I am not sure on is how to get it to accept --arg when using ./script.php. if I do

php clitest.php --with-cheese

it outputs

[daemorhedron@obsidian daemorhedron]$ php clitest.php --with-cheese
Content-type: text/html

Array
(
[0] => clitest.php
[1] => --with-cheese
)

Anyways, HTH.
Post Reply