Jump to content
  • Advertisement
Sign in to follow this  
intransigent-seal

Pipe both ways?

This topic is 4839 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Any half-decent command line shell has a syntax to let you "pipe" the output stream from one application to the input stream of another application, eg:
grep -ri foo * | sort | uniq
However, I don't know of a syntax to set up a two-way pipe. Something like (with an invented syntax):
foo || bar
Would pipe stdout of foo to stdin of bar but also pipe stdout of bar back to stdin of foo. Is this capability supported on any shells that you know of? I'm on windows by the way, and currently using the standard win xp command line, but I would be happy to switch to a better replacement, if it ran entirely natively - I'd prefer to avoid cygwin, but not for any good reasons, so I may switch to that eventually. Admittedly there are (probably) fewer uses for a two-way pipe than the universal one-way pipe, but I can think of at least one thing that could be useful on occasion: A super-simple command line network application that will just open a TCP connection and sit there, redirecting network traffic onto the standard input/output streams, so that you can pipe it into protocol-specific scripts or other command line utilities. John B

Share this post


Link to post
Share on other sites
Advertisement
I don't know of any shell that supports them natively but they're technically trivial setup.
I've seen a few applications which accepts the other application's name arguments on the command line and executes it through a bidirectional pipe, including a TCP daemon much like what you suggested yourself.
One could of course write a generic "connection" program that does the same thing with two children too.

edit: A quick google session found twinpipe.

A Unix application could simply connect a TCP socket, use dup2() the override the stdio handles and exec() the requested application.
I have no idea how to do this on Win32 though, this is the kind of thing that Unix was made for. But isn't Win32 supposed to have some kind of POSIX layer?

Share this post


Link to post
Share on other sites
I'm confused. If "x | y" means "pipe stdout of x into stdin of y"; and you want "pipe stdout of x into stdin of y && pipe stdout of y into stdin of x", then doesn't "foo | bar | foo" do what you want? Or is it important that the same instance of foo be used in both cases?

Share this post


Link to post
Share on other sites
Quote:
Original post by doynax
I don't know of any shell that supports them natively but they're technically trivial setup.
I've seen a few applications which accepts the other application's name arguments on the command line and executes it through a bidirectional pipe, including a TCP daemon much like what you suggested yourself.
One could of course write a generic "connection" program that does the same thing with two children too.

edit: A quick google session found twinpipe.

Ah, thank you.

edit: And, kSquared, yes, I meant the same instance not just the same application - sorry I wasn't clear.

John B

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!