I'm assuming, since you mentioned bash and tcsh that you're in Linux or Unix.
I've always used stty in conjunction with dd for this kind of thing. For example, the following should help you get there:
use strict; use warnings; $| = 1; print "Enter some characters below, <Escape> to quit\n"; chomp(my $stty = `stty -g`); # Save state system("stty -icrnl -icanon -echo min 0 time 0"); # Raw mode while (1) { my $k = `dd bs=1 count=1 <&0 2>/dev/null`; next unless $k; # No character entered last if (27 == ord $k); # Finish if char is <Escape> printf "Ascii = %d\n", ord($k); } system("stty $stty"); # Restore cooked mode (thanks, sgt!) print "\nDone!\n";
It reads characters one at a time, displaying their ascii value, until you type an Escape. Of course, you could easily modify it to read only a single character, or as many as you need.
Good luck!
Update: Good catch sgt. I've added the line system("stty $stty"); to restore "cooked" mode.
In reply to Re: y/n input in a captive interface
by liverpole
in thread y/n input in a captive interface
by apotheon
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |