php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28247 CLI sapi option -R does not work as expected
Submitted: 2004-05-01 23:56 UTC Modified: 2004-05-02 11:16 UTC
From: aaron at wormus dot com Assigned: helly (profile)
Status: Not a bug Package: CGI/CLI related
PHP Version: 5.0.0RC2 OS: *
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: aaron at wormus dot com
New email:
PHP Version: OS:

 

 [2004-05-01 23:56 UTC] aaron at wormus dot com
Description:
------------
the following command line script does not work as (I) expected.

php -R "echo fgets(STDIN);"

Instead of echoing every line, it echos every OTHER line. I am not sure if this is the expected behaviour. I suspect something to be wrong. If it is meant to happen, I would appreciate a short explaination :) I'm writing an article on the CLI SAPI and this one is stumping me!

Aaron

Reproduce code:
---------------
php -R "echo fgets(STDIN);"

Expected result:
----------------
I expected it to work like:

perl -e "while (<STDIN>){print}"

echoing every line as you type it.



Actual result:
--------------
Echoes every OTHER line

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-05-02 10:02 UTC] aaron at wormus dot com
The original test that demonstrates this better is: 

cat file.txt | php -B "echo ++$num. ' ';" -R "echo ++$num. ' '.fgets(STDIN);"
 [2004-05-02 10:42 UTC] helly@php.net
I don't think this is expected behavior.

As a workaround you can do this for now:
ll CVS|php -R 'echo $argn."\n";'
 [2004-05-02 11:16 UTC] helly@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Looking at the code again it is expexcted behavior indeed.

Both the internal line fetching and STDIN obviously operate on the same input stream. Therefore the code:
php -R 'echo $argn."\n".fgets(STDIN);'
shows every input line. In other words reading STDIN
changes the next input line or skips them.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 31 23:01:28 2024 UTC