Re: unix pipes to perl scripts
From: Josef Moellers (josef.moellers_at_fujitsu-siemens.com)
Date: 03/14/05
- Next message: Chris Mattern: "Re: unix pipes to perl scripts"
- Previous message: trt.: "Re: unix pipes to perl scripts"
- In reply to: trt.: "unix pipes to perl scripts"
- Next in thread: Chris Mattern: "Re: unix pipes to perl scripts"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 14 Mar 2005 15:33:53 +0100
trt. wrote:
> Got a problem piping command output to a perl script, in the test below
> the loop accepts the piped files but it also interferes with my STDIN!
>
> ===test=============================
> $ls -1 *.cfg | ./pp
> file: hosts.cfg
> file: pseries.cfg
>
> type something : you typed :
> ===test=============================
>
> I do not get the chance to type something in after "type something"...
>
> Do i have to flush some variable inbetween the foreach loop and
> <STDIN>?
> Is looping trough <ARGV> or <> the best way to catch piped input?
The STDIN of your pp script is redirected from the keyboard to the
STDOUT of the ls command. It is not automagically reconnected to the
keyboard once the ls command has terminated.
It would not be a good idea to reconnect to the keyboard, as quite a lot
of scripts depend upon pipelines to perform certain tasks (this is a
design feature of the UN*X/Linux architecture).
If you must read some more input from the keyboard, you can open /dev/tty:
#!/usr/bin/perl
while ( <> ) {
print "file: $_";
};
open STDIN, '<', '/dev/tty'; #################################
print "\ntype something : ";
$answer = <STDIN>;
print "you typed : $answer \n";
Note that you'll get problems with buffering, though.
Josef
-- Josef Möllers (Pinguinpfleger bei FSC) If failure had no penalty success would not be a prize -- T. Pratchett
- Next message: Chris Mattern: "Re: unix pipes to perl scripts"
- Previous message: trt.: "Re: unix pipes to perl scripts"
- In reply to: trt.: "unix pipes to perl scripts"
- Next in thread: Chris Mattern: "Re: unix pipes to perl scripts"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|