Checking for keyboard input without halting process

From: Zikester (ikeb_at_storm.ca)
Date: 04/29/04


To: beginners@perl.org
Date: Thu, 29 Apr 2004 02:53:26 -0400

I've racked my brain for an answer to this one. Probably real simple.....

I'd like to run a process reatedly until entering a character on the
keyboard (other than ^C). When the character is entered the process would
complete some final tasks and exit the program.

do {
    # a process
$Keyboard_Input = (check_for_input);
} until ($Keyboard_Input);
# some final tasks

I've tried to use the standard input file <STDIN> without success.
I've tried
$Keyboard_Input = <STDIN>; which just halts the script until the Enter key
is pressed.
$Keyboard_Input = eof (STDIN); which halts until the Enter key is pressed
and then returns a null character thereafter
$Keyboard_Input = tell (STDIN); which returns a '0' character even if the
Enter key is pressed,

OK, so what am I missing here? Do I need to use something other than the
Standard Input File structure?



Relevant Pages

  • Re: Curious MySQL building problem /w GCC 3.4.2
    ... >> for some reason waiting for something from stdin, so I typed the EOF ... >> character on the keyboard and that allowed the as process to continue. ...
    (freebsd-current)
  • Re: output problem
    ... This line reads characters from stdin and stores ... When it finds a non-white character, ... Just as with the first scanf(), ... amount of white space from the input. ...
    (comp.lang.c)
  • Re: output problem
    ... This line reads characters from stdin and stores ... When it finds a non-white character, ... Just as with the first scanf(), ... this call will discard the left-over '\n', store "Wiener" ...
    (comp.lang.c)
  • Re: Program entering the default case of switch statement always
    ... characters don't appear in stdin, ... sequence of characters terminated with a newline character. ... So getchar, getc, fgetc wait until a character appears. ... The third time through the loop, stdin is once again empty, ...
    (comp.lang.c)
  • Re: program waits before the select system call
    ... A> time from the stdin. ... A> character of whatever i type on stdin and then it just hangs before ... A> int tstGetInput; ...
    (comp.unix.aix)