Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Emulating the cmd line pipe

by BUU (Prior)
on Aug 05, 2002 at 22:22 UTC ( [id://187845]=perlquestion: print w/replies, xml ) Need Help??

BUU has asked for the wisdom of the Perl Monks concerning the following question:

This is mostly for my own amuse ment, but would something like:
open I,'| myInProg'; open O,'myOutProg |'; print O while <I>;
Basically emulate myInProg | myOutProg ?

Replies are listed 'Best First'.
Re: Emulating the cmd line pipe
by I0 (Priest) on Aug 05, 2002 at 22:31 UTC
    open I,'myInProg|'; open O,'|myOutProg'; print O while <I>;
Re: Emulating the cmd line pipe
by graff (Chancellor) on Aug 06, 2002 at 02:50 UTC
    IO's reply fixes your reversal of I and O file handles (though it took me a while to see that...)

    It's a simple enough thing to try (did you?), and the only thing missing is that you have to make sure to close O; after the "while" loop is done, or else the script won't exit.

    It would be interesting to see whether using this approach on MS-Windows might allow for pipes that work more like unix pipes.

    Based on observation, I believe the difference between unix and ms-windows/dos pipline operations goes like this:

    On unix:

    • start all processes involved in the pipeline
    • keep data flowing through the pipe till something quits.

    On windows/dos:

    • run the first process in the pipeline and put its output somewhere
    • when that one finishes, start the next process and pass it the output created by the previous process
    • when that one finishes, start the next one...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://187845]
Approved by osfameron
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2024-03-19 06:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found