in reply to Re^2: the greedy diamond, or leggo my STDIN
in thread the greedy diamond, or leggo my STDIN
Sounds like that would work, but isn't there a way to just switch my STDIN back to the keyboard?
Nope, because it's not been switched forth. It has been switched away once and for all out of your program. Of course you can reopen STDIN to whatever you want, if you like:
q:~/tmp [22:27:50]$ cat headybrew.pl #!/usr/bin/perl chomp(my @msg =<>); print @msg, "\n"; print "What do you want to do with this message?"; close STDIN; open STDIN, '<', '/dev/tty' or die "Can't read from /dev/tty: $!\n"; my $response = <STDIN>; print $response; q:~/tmp [22:27:58]$ ls | ./headybrew.pl headybrew.plheadybrew.pl~ What do you want to do with this message?foo foo q:~/tmp [22:28:08]$
But then you rely on something hardcoded that you know or want to be the keyboard. Because from within your program you have no notion of "what" the keyboard would have been, had STDIN not been redirected by the shell.
|
|---|