Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PipingSTDIN

Status
Not open for further replies.

gnikol1

IS-IT--Management
Jan 30, 2002
29
EU
Hello to all

I would like to run an executable and pipe the output like below

parser | script.pl

How do I do that?

 
do you mean from inside another perl script? if you do the answer is:

system('parser | script.pl'); Mike
"Experience is the comb that Nature gives us after we are bald."

Is that a haiku?
I never could get the hang
of writing those things.
 
and if you mean you want to pipe from the command line then the information goes to the filehandle <STDIN> which you can parse or print or do whatever.
 
NOt exactly.
I want the output of the pasrser to input to the perl scripts
 
ok

open(P, 'parser |') || die &quot;Can't run parser\n$!\n&quot;;
while(<P>){
print $_; # each line of output from parser will be in $_
} Mike
&quot;Experience is the comb that Nature gives us after we are bald.&quot;

Is that a haiku?
I never could get the hang
of writing those things.
 
Thanks
I believe that is the same as

while (<STDIN>)
{
print &quot;$_\n&quot;;
}
 
&quot;It is not the same as ......&quot;

Unless you do something tricky to attach STDIN to a specific process, it is not the same.

Mike, is correct. You need to open a pipe to the parser process and 'listen' to that PIPE. STDOUT from that process will come in the pipe.


'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
I think he means its the same as:

at the command line:
$ parser | script.pl

and in script.pl:

while (<STDIN>)
{
print &quot;$_\n&quot;;
}
 
yes, it's like that Yauncin, but you get some more control as well, like this example from the documentation.

open(SPOOLER, &quot;| cat -v | lpr -h 2>/dev/null&quot;)
|| die &quot;can't fork: $!&quot;;
local $SIG{PIPE} = sub { die &quot;spooler pipe broke&quot; };
print SPOOLER &quot;stuff\n&quot;;
close SPOOLER || die &quot;bad spool: $! $?&quot;;
Mike
&quot;Experience is the comb that Nature gives us after we are bald.&quot;

Is that a haiku?
I never could get the hang
of writing those things.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top