#!/usr/bin/perl use warnings; use strict; # readstream.pl use Fcntl; fcntl(STDIN, F_SETFL, O_NONBLOCK); my $input; my $res; my $str = ""; my $reading = 0; my $notread = 0; while(1) { $res = sysread(STDIN, $input, 1); if (defined($res)) { $reading = 1; $str .= $input; if ($notread) { print "Unsuccessful attempts to read: $notread.\n"; } $notread = 0; } else { if ($reading == 1) { print $str; } $reading = 0; $notread++; $str = ""; } }