note 105096 added to features.commandline.io-streams
| From: | ecrist at secure-computing dot net | Date: | Wed, 27 Jul 2011 15:15:19 +0000 |
| Subject: | note 105096 added to features.commandline.io-streams | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-181935@lists.php.net to get a copy of this message | ||
The following code shows how to test for input on STDIN. In this case, we were looking for CSV
data, so we use fgetcsv to read STDIN, if it creates an array, we assume CVS input on STDIN, if no
array was created, we assume there's no input from STDIN, and look, later, to an argument with
a CSV file name.
Note, without the stream_set_blocking() call, fgetcsv() hangs on STDIN, awaiting input from the
user, which isn't useful as we're looking for a piped file. If it isn't here already,
it isn't going to be.
<?php
stream_set_blocking(STDIN, 0);
$csv_ar = fgetcsv(STDIN);
if (is_array($csv_ar)){
print "CVS on STDIN\n";
} else {
print "Look to ARGV for CSV file name.\n";
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 173.8.118.221
----
Manual Page -- http://www.php.net/manual/en/features.commandline.io-streams.php
Edit -- https://master.php.net/note/edit/105096
Del: integrated -- https://master.php.net/note/delete/105096/integrated
Del: useless -- https://master.php.net/note/delete/105096/useless
Del: bad code -- https://master.php.net/note/delete/105096/bad+code
Del: spam -- https://master.php.net/note/delete/105096/spam
Del: non-english -- https://master.php.net/note/delete/105096/non-english
Del: in docs -- https://master.php.net/note/delete/105096/in+docs
Del: other reasons-- https://master.php.net/note/delete/105096
Reject -- https://master.php.net/note/reject/105096
Search -- https://master.php.net/manage/user-notes.php