in reply to Re: Timeout on STDIN
in thread Timeout on STDIN
I am trying zentaras snippet, and failing...
my perl script got started as a child process, so the parent communicates via STDIN to my script. There is no real keyboard involved. Unfortunately I'm not really up to speed on terminals and tty. I'm wondering if Term::ReadKey should work in that case.
This is a win32 application
sub get_stdin_w_timeout { ######!/usr/bin/perl #got from zentara on perl monks in response to Timeout on STDIN #modifying to use ReadKey to get first key and then <STDIN> to get t +he rest of the line #this function assumes that once there is some input on stdin, #the rest of the line is available too use strict; use warnings; use Term::ReadKey; my $timeout_in_sec=shift; my $end_time = time + $timeout_in_sec; my $key=""; do { my $key = ReadKey(1); if (defined $key) { #not sure if I need to concatenate $key on the front of <STDIN> return $key. <STDIN>; } } while (time < $end_time ); return "!ERROR!:Timed out waiting on input after ${timeout_in_sec}s\ +n"; }
when i run this like this
$plibMsg=&get_stdin_w_timeout(5);#<STDIN>;
I always get the Timed out message
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Timeout on STDIN
by soonix (Chancellor) on Oct 14, 2016 at 09:35 UTC | |
by boleary (Scribe) on Oct 24, 2016 at 10:52 UTC | |
by soonix (Chancellor) on Oct 24, 2016 at 11:43 UTC | |
by boleary (Scribe) on Oct 24, 2016 at 14:25 UTC |