Q on php://stdin
| From: | Billy S Halsey | Date: | Mon, 18 Feb 2002 11:10:10 +0000 |
| Subject: | Q on php://stdin | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-85173@lists.php.net to get a copy of this message | ||
Hi all,
I've been trying for the last three hours to do something like this:
#!/usr/local/bin/php -q
<?php
$fp = fopen("php://stdin", "r");
while (!feof($fp)) {
$line = fgets($fp, 4096);
print $line;
}
fclose($fp);
?>
And then calling it with something like:
cat foo.txt | ./echofile.php
The problem is, it will print the first line of foo.txt, and then exit. No matter what I do, I can't get it to read the next line. I've even added a test after the print command to see if it's at EOF, and it's not. I've also changed it to do this:
while (($buf = fgets($fp, 4096)) != FALSE) {
print $buf;} Still won't read more than one line of the file. The only thing I've been able to do that seems to work is this: $fp = fopen("/dev/fd/0", "r"); while (!feof($fp)) ...... [The code snippets I've quoted above are just rough sketches ... I really am checking the return value from fopen() to make sure I open the file, etc.] I'm using PHP 4.1.1 on Solaris 8. Can somebody PLEASE tell me what the problem is? What stupid mistake am I making? Thanks. -bsh :-) -- ======================================================================= Billy S Halsey Software Problem Resolution ESP Solaris Software Email Billy.Halsey@Sun.COM Sun Microsystems, Inc -NO DAY BUT TODAY- =======================================================================