What does this command do: "|-"

HI,

I have started learning PERL recently. I wanted some explaination regarding 
the following command.

open(FILE, "|-")

What does this command do?

Thanks
Shilpa


0
shilparvind
4/23/2004 6:21:03 PM
perl.beginners 29388 articles. 4 followers. Follow

8 Replies
332 Views

Similar Articles

[PageSpeed] 51
Get it on Google Play
Get it on Apple App Store

Shilpa Arvind wrote:
> HI,
> 
> I have started learning PERL recently. I wanted some explaination 
> regarding the following command.
> 
> open(FILE, "|-")
> 
> What does this command do?

open

Forks with the file connected to the STDIN of the child process.

-- 
_Sx_ http://youve-reached-the.endoftheinternet.org/ 
_________________________________________________________________
perl -MMIME::Base64 -e 'print 
decode_base64("SnVzdCBvbmUgbW9yZSBQb3N0Zml4IDIuMnggU25hcHNob3QgRmlsdGVyLCBwbGVhc2UK");'
0
WC
4/23/2004 6:21:37 PM
This means that, whatever the child process does will the output for the 
parent process and it will be stored in the FILE (file handle).

Shilpa


>From: WC -Sx- Jones <WC-Sx-Jones@insecurity.org>
>Reply-To: beginners@perl.org
>To: Shilpa Arvind <shilparvind@hotmail.com>
>CC: beginners@perl.org
>Subject: Re: What does this command do: "|-"
>Date: Fri, 23 Apr 2004 14:21:37 -0400
>
>Shilpa Arvind wrote:
>>HI,
>>
>>I have started learning PERL recently. I wanted some explaination 
>>regarding the following command.
>>
>>open(FILE, "|-")
>>
>>What does this command do?
>
>open
>
>Forks with the file connected to the STDIN of the child process.
>
>--
>_Sx_ http://youve-reached-the.endoftheinternet.org/ 
>_________________________________________________________________
>perl -MMIME::Base64 -e 'print 
>decode_base64("SnVzdCBvbmUgbW9yZSBQb3N0Zml4IDIuMnggU25hcHNob3QgRmlsdGVyLCBwbGVhc2UK");'


0
shilparvind
4/23/2004 6:29:22 PM
Shilpa Arvind wrote:
> This means that, whatever the child process does will the output for the 
> parent process and it will be stored in the FILE (file handle).

>>> open(FILE, "|-")
>>>
>>
>> Forks with the file connected to the STDIN of the child process.


No, it means that what you read out of <FILE> will be input for *child

See
perldoc perlopentut

-- 
_Sx_ http://youve-reached-the.endoftheinternet.org/ 
_________________________________________________________________
perl -MMIME::Base64 -e 'print 
decode_base64("SnVzdCBvbmUgbW9yZSBQb3N0Zml4IDIuMnggU25hcHNob3QgRmlsdGVyLCBwbGVhc2UK");'
0
WC
4/23/2004 6:35:44 PM
Can u explain this little bit clearly.

Shilpa

>From: WC -Sx- Jones <WC-Sx-Jones@insecurity.org>
>Reply-To: beginners@perl.org
>To: Shilpa Arvind <shilparvind@hotmail.com>
>CC: beginners@perl.org
>Subject: Re: What does this command do: "|-"
>Date: Fri, 23 Apr 2004 14:21:37 -0400
>
>Shilpa Arvind wrote:
>>HI,
>>
>>I have started learning PERL recently. I wanted some explaination 
>>regarding the following command.
>>
>>open(FILE, "|-")
>>
>>What does this command do?
>
>open
>
>Forks with the file connected to the STDIN of the child process.
>
>--
>_Sx_ http://youve-reached-the.endoftheinternet.org/ 
>_________________________________________________________________
>perl -MMIME::Base64 -e 'print 
>decode_base64("SnVzdCBvbmUgbW9yZSBQb3N0Zml4IDIuMnggU25hcHNob3QgRmlsdGVyLCBwbGVhc2UK");'


0
shilparvind
4/23/2004 6:37:30 PM
Thanks a lot.

>From: WC -Sx- Jones <WC-Sx-Jones@insecurity.org>
>Reply-To: beginners@perl.org
>To: Shilpa Arvind <shilparvind@hotmail.com>
>CC: beginners@perl.org
>Subject: Re: What does this command do: "|-"
>Date: Fri, 23 Apr 2004 14:35:44 -0400
>
>Shilpa Arvind wrote:
>>This means that, whatever the child process does will the output for the 
>>parent process and it will be stored in the FILE (file handle).
>
>>>>open(FILE, "|-")
>>>>
>>>
>>>Forks with the file connected to the STDIN of the child process.
>
>
>No, it means that what you read out of <FILE> will be input for *child
>
>See
>perldoc perlopentut
>
>--
>_Sx_ http://youve-reached-the.endoftheinternet.org/ 
>_________________________________________________________________
>perl -MMIME::Base64 -e 'print 
>decode_base64("SnVzdCBvbmUgbW9yZSBQb3N0Zml4IDIuMnggU25hcHNob3QgRmlsdGVyLCBwbGVhc2UK");'
>
>--
>To unsubscribe, e-mail: beginners-unsubscribe@perl.org
>For additional commands, e-mail: beginners-help@perl.org
><http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>


0
shilparvind
4/23/2004 6:40:25 PM
Shilpa Arvind wrote:

> HI,
> 
> I have started learning PERL recently. I wanted some explaination
> regarding the following command.
> 
> open(FILE, "|-")
> 

Perl implicitly forks a child process. the FILE file handle is opened with 
write access in the parent process. what the parent process writes to FILE 
can be read by the child process via STDIN. this allows you to do simple 
ipc communication between the parent and the child process. for example:

#!/usr/bin/perl -w
use strict;

$SIG{CHLD} = 'IGNORE';

my $id = open(FILE,'|-');

die unless defined $id;

if($id){
        select(FILE); $| = 1;
        while(<>){
                last if /quit/i;
                print FILE;
        }
}else{
        while(<>){
                chomp;
                print length,"\n";
        }
}

__END__

[panda]# open.pl
abcd
4
1234567890
10
xyz
3
quit
[panda]#

david
-- 
s$s*$+/<tgmecJ"ntgR"tgjvqpC"vuwL$;$;=qq$
\x24\x5f\x3d\x72\x65\x76\x65\x72\x73\x65
\x24\x5f\x3b\x73\x2f\x2e\x2f\x63\x68\x72
\x28\x6f\x72\x64\x28\x24\x26\x29\x2d\x32
\x29\x2f\x67\x65\x3b\x70\x72\x69\x6e\x74
\x22\x24\x5f\x5c\x6e\x22\x3b\x3b$;eval$;
0
dzhuo
4/23/2004 9:15:26 PM

>> HI,
>> 
>> I have started learning PERL recently. I wanted some explaination
>> regarding the following command.
>> 
>> open(FILE, "|-")
>> 
> 
> Perl implicitly forks a child process. the FILE file handle is opened with
> write access in the parent process. what the parent process writes to FILE
> can be read by the child process via STDIN. this allows you to do simple
> ipc communication between the parent and the child process. for example:

[stuff cut out]

Why would you ever do this?  When would this be used?

- Bryan

0
harrisb
4/24/2004 9:26:39 PM
Bryan Harris wrote:

>>Perl implicitly forks a child process. the FILE file handle is opened with
>>write access in the parent process. what the parent process writes to FILE
>>can be read by the child process via STDIN. this allows you to do simple
>>ipc communication between the parent and the child process. for example:

> Why would you ever do this?  When would this be used?


Like it says - to feed data to anothe rprocess - maybe an external 
program.  Or, as in my case, talking to yourself -

http://iis1.cps.unizar.es/Oreilly/perl/prog/ch06_02.htm#PERL2-CH-6-SECT-2.2.2

-- 
_Sx_ http://youve-reached-the.endoftheinternet.org/ 
_________________________________________________________________
perl -MMIME::Base64 -e 'print 
decode_base64("SnVzdCBvbmUgbW9yZSBQb3N0Zml4IDIuMnggU25hcHNob3QgRmlsdGVyLCBwbGVhc2UK");'
0
WC
4/25/2004 10:24:36 PM
Reply: