The question is, how does the program run with the standard input using the "<" symbol or the "|" Conforms to a file that is directed at the command line.
However, in the process of running the program to get input from the keyboard.
Because/dev/tty is the console for the current process, it STDIN
is entered for the current standard. If redirected, for example:
Perl script.pl <myfile.txt
STDIN
Be pointed tomyfile.txt
But/dev/tty
Stillfrom the control terminal. All UNIX is like this, not just referring to this perl.
Then the solution:
#!/usr/bin/perl-wuse strict;$| = 1;my $stream; while (<>) {$stream. = $_;} Open STDIN, "/dev/tty" or die;print "does you want to process the stream?"; My $ans = <stdin>;chomp $ans;p rint "Got" $ans ' \ n ';p rint "stream = $stream"; #...exit;__end__
Test:
$ echo Foo |./stdin does want to process the stream? Yesgot ' yes ' stream = Foo
Find the standard input to re-point to the keyboard. Problem solving. Good luck, June.
This article is from the "EIT Tramp" blog, please be sure to keep this source http://zicowarn.blog.51cto.com/3815716/1708173
Perl questions about re-opening standard input during program operation