Re: Asking for input from shell?

From: Date: Thu, 01 Jan 1970 00:00:00 +0000
Subject: Re: Asking for input from shell?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-47767@lists.php.net to get a copy of this message
Try this instead : #! /local/bin/php -q <?PHP // -*- C++ -*- function read() { $fp=fopen( "/dev/stdin", "r"); $input=fgets($fp, 255); fclose($fp); return eregi_replace("\n","",$input); } function clear(){ system("/bin/clear",$retvar); if ( $retvar != 0 ) { print "error\n"; exit; } return 0; } // endfunction print "How old are you ? : "; $age = read(); print "\nWhat\'s your name ? :"; $name = read(); print "You are $name and are $age old\n"; ?> On Mon, 9 Apr 2001, enthalpy wrote: > when using this more then once in a script i get errors > even though the file pointers are different. > > echo "Artist: "; > $artist = fopen("php://stdin", "r"); > echo fgets($artist, 64); > fclose($artist); > echo "\n"; > > echo "Album: "; > $album = fopen("php://stdin", "r"); > echo fgets($album, 64); > fclose($album); > echo "\n"; > > --------------------------- > Errors: > > <b>Warning</b>: fopen("php://stdin","r") - Bad file descriptor > in <b>./addvinyl.php</b> on line <b>11</b><br> > <br> > <b>Warning</b>: Supplied argument is not a valid File-Handle resource in > <b>./addvinyl.php</b> on line <b>12</b><br> > <br> > <b>Warning</b>: Supplied argument is not a valid File-Handle resource in > <b>./addvinyl.php</b> on line <b>13</b><br> > > > > > <-----CoreComm-Internet-Services---http://core.com-----> > (Jon Marshall CoreComm Services Chicago) > (jonathon.marshall@core.com Systems Engineer II) > (enthalpy@core.com Network Operations) > <-----Enthalpy.org-------------http://enthalpy.org-----> > (enthalpy@enthalpy.org The World of Nothing) > <------------------------------------------------------> > > On Mon, 9 Apr 2001, Jason Brooke wrote: > > > $fp = fopen("php://stdin", "r"); > > echo fgets($fp, 64); > > fclose($fp); > > > > ----- Original Message ----- > > From: "enthalpy" <enthalpy@core.com> > > To: <php-general@lists.php.net> > > Sent: Monday, April 09, 2001 1:10 PM > > Subject: [PHP] Asking for input from shell? > > > > > > > > > > anyone have sample code of how you can have a php script (cgi) > > > ask for input from the shell? > > > > > > > > > <-----CoreComm-Internet-Services---http://core.com-----> > > > (Jon Marshall CoreComm Services Chicago) > > > (jonathon.marshall@core.com Systems Engineer II) > > > (enthalpy@core.com Network Operations) > > > > > > <-----Enthalpy.org-------------http://enthalpy.org-----> > > > (enthalpy@enthalpy.org The World of Nothing) > > > <------------------------------------------------------> > > > > > > > > > -- > > > PHP General Mailing List (http://www.php.net/) > > > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > > > For additional commands, e-mail: php-general-help@lists.php.net > > > To contact the list administrators, e-mail: php-list-admin@lists.php.net > > > > > > > > > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > > For additional commands, e-mail: php-general-help@lists.php.net > > To contact the list administrators, e-mail: php-list-admin@lists.php.net > > > > > > > -- Knut ------ Knut H. Hassel Nielsen Principal Engineer / Avdelingsingeniør Norwegian University of Science and Technology / NTNU Department of Computer and Information Science / IDI N-7491 Trondheim, Norway Phone Office / Telefon jobb : (+47) 73 59 18 46 Fax Office / Telefax jobb : (+47) 73 59 17 33 Cell. Phone / Mobiltelefon : 91 59 86 06

« previous php.general (#47767) next »