I am writing a script that can read from stdin and then ask for confirmation.
<?php $stream = fopen('php://stdin', 'r'); $input = fgets($stream, 1024); $confirmation = readline('Are you sure?'); if ( $confirmation == 'y' )
When I run it directly:
$ PHP .php inputdata ^D Are you sure?
But I'm trying to run it using the file as STDIN. In this case, readline () returns false and no confirmation is requested.
$ PHP .php < data.txt
or
$ echo "foobar" | PHP .php
How can I read both from STDIN and keyboard when calling this script this way?
Thanks.
source share