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)
> ([EMAIL PROTECTED] Systems Engineer II)
> ([EMAIL PROTECTED] Network Operations)
> <-----Enthalpy.org-------------http://enthalpy.org----->
> ([EMAIL PROTECTED] 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" <[EMAIL PROTECTED]>
> > To: <[EMAIL PROTECTED]>
> > 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)
> > > ([EMAIL PROTECTED] Systems Engineer II)
> > > ([EMAIL PROTECTED] Network Operations)
> > > <-----Enthalpy.org-------------http://enthalpy.org----->
> > > ([EMAIL PROTECTED] The World of Nothing)
> > > <------------------------------------------------------>
> > >
> > >
> > > --
> > > PHP General Mailing List (http://www.php.net/)
> > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > For additional commands, e-mail: [EMAIL PROTECTED]
> > > To contact the list administrators, e-mail: [EMAIL PROTECTED]
> > >
> > >
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> > To contact the list administrators, e-mail: [EMAIL PROTECTED]
> >
> >
>
>
>
--
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
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]