Hi all,
I still have been completely unable to get this to work like it should.
I have a simple script:
#!/usr/local/bin/php -q
<?php
$fp = fopen("php://stdin", "r");
while (($buf = fgets($fp, 512)) != false) {
$input .= $buf;
}
echo "$input";
?>
So if I call this echo.php, then if I try something like
cat /etc/hosts | ./echo.php
It prints a # (first line of /etc/hosts) followed by two blank lines.
Then it quits. /etc/hosts does contain real data. This occurs with ANY
file that I try to cat.
If you know what the problem might be, I would LOVE to hear your
suggestions. I didn't get any replies the first time I asked, so I'm
hoping that someone has something to contribute.
I'm using PHP 4.1.1 on Solaris 8.
Thanks in advance,
-bsh
Billy S Halsey wrote:
> 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 [EMAIL PROTECTED] Sun Microsystems, Inc
-NO DAY BUT TODAY-
=======================================================================
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php