Forum: Ruby Bi-directional pipe?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
753dcb78b3a3651127665da4bed3c782?d=identicon&s=25 Brian Candler (Guest)
on 2007-03-13 21:15
(Received via mailing list)
Is there any standard Ruby way of creating a bidirectional pipe or
socketpair?

I want to pass a single IO-like object around, but to be able to both
read
and write from the other end. (What I'm actually trying to do is to put
a
facade around Net::SSH so that the command channel can be passed in as a
proxy to Net::Telnet, but I can think of other uses of this)

IO.popen(..., "w+") does make such a bidirectional pipe, but as far as I
can
see only for communicating with a child process.

Any ideas?

Thanks,

Brian.
Ef3aa7f7e577ea8cd620462724ddf73b?d=identicon&s=25 Rob Biedenharn (Guest)
on 2007-03-13 21:29
(Received via mailing list)
On Mar 13, 2007, at 4:15 PM, Brian Candler wrote:
>
> IO.popen(..., "w+") does make such a bidirectional pipe, but as far
> as I can
> see only for communicating with a child process.
>
> Any ideas?
>
> Thanks,
>
> Brian.

rd, wr = IO.pipe

comes to mind.

-Rob

Rob Biedenharn    http://agileconsultingllc.com
Rob@AgileConsultingLLC.com
Cb48ca5059faf7409a5ab3745a964696?d=identicon&s=25 unknown (Guest)
on 2007-03-13 21:36
(Received via mailing list)
On Wed, 14 Mar 2007, Rob Biedenharn wrote:

> On Mar 13, 2007, at 4:15 PM, Brian Candler wrote:
>> Is there any standard Ruby way of creating a bidirectional pipe or
>> socketpair?

require 'socket'
Socket.pair ....


-a
753dcb78b3a3651127665da4bed3c782?d=identicon&s=25 Brian Candler (Guest)
on 2007-03-13 22:00
(Received via mailing list)
On Wed, Mar 14, 2007 at 05:29:16AM +0900, Rob Biedenharn wrote:
> >proxy to Net::Telnet, but I can think of other uses of this)
>
> rd, wr = IO.pipe
>
> comes to mind.

That's a *unidirectional* pipe. At least, all the rdoc stuff says that
one
end is a reader and the other end is a writer.
753dcb78b3a3651127665da4bed3c782?d=identicon&s=25 Brian Candler (Guest)
on 2007-03-13 22:02
(Received via mailing list)
On Wed, Mar 14, 2007 at 05:35:52AM +0900, ara.t.howard@noaa.gov wrote:
> On Wed, 14 Mar 2007, Rob Biedenharn wrote:
>
> >On Mar 13, 2007, at 4:15 PM, Brian Candler wrote:
> >>Is there any standard Ruby way of creating a bidirectional pipe or
> >>socketpair?
>
> require 'socket'
> Socket.pair ....


irb(main):015:0> require 'socket'
=> true
irb(main):016:0> a = Socket.pair
ArgumentError: wrong number of arguments (0 for 3)
        from (irb):16:in `pair'
        from (irb):16
        from :0

OK, so it exists, it's just not documented in ri - time to grep the
source I
guess. Thanks for the pointer.
Cb48ca5059faf7409a5ab3745a964696?d=identicon&s=25 unknown (Guest)
on 2007-03-13 22:17
(Received via mailing list)
On Wed, 14 Mar 2007, Brian Candler wrote:

>
> irb(main):015:0> require 'socket'
> => true
> irb(main):016:0> a = Socket.pair
> ArgumentError: wrong number of arguments (0 for 3)
>        from (irb):16:in `pair'
>        from (irb):16
>        from :0
>
> OK, so it exists, it's just not documented in ri - time to grep the source I
> guess. Thanks for the pointer.

http://groups.google.com/group/comp.lang.ruby/brow...

http://groups.google.com/group/comp.lang.ruby/brow...

regards.

-a
This topic is locked and can not be replied to.