STDIN is only working randomly

So I have this script that changes the color of the text in the console. The problem is that although it accepts a string from both STDIN and the -s argument, it will occasionally leave out STDIN in the result. I have only noticed this when I pipe the script to itself (see below)

php color.php -s Hello, -c green -S underline | php color.php -s " Bob" -c red -S bold

The bash script above would always show " Bob" but would only show "Hello," a few times in a series of tries, without changing any part of the script. As far as I can tell, whether it includes it or not is very random, there is no noticeable pattern.

So my question is, how do I prevent this?


Reading non-blocking might not have the data there yet. Another option is only to read STDIN if the input is not an interactive terminal:

$args = getopt('s:');
        $stdin = file_get_contents('php://stdin');
} else {
        $stdin ='';
echo $stdin.' '.$args['s'];

Need Your Help

Image container with fixed size

html css

I have the following image container :

ViewModel not being passed back to controller in POST method


Simple problem, but I can't figure out what is missing. I have a simple ViewModel (it'll get bigger):