[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Reading from a named pipe

Günther Gruber

11/17/2006 10:06:00 AM

Hi all,

I need to read some text from a named pipe in ruby. The writing is done
in another (C++) program and I'd like to have Ruby display what is sent.

I've looked at the IO.pipe function, but there seems to be no way to get
a NAMED pipe. The two programs are running under Windows XP, btw.

Are named pipes even supported in Ruby? How can I read from one? Thanks
for your answers! :)

--
Posted via http://www.ruby-....

4 Answers

Paul Lutus

11/17/2006 11:04:00 AM

0

Gc3bcnther Gruber wrote:

> Hi all,
>
> I need to read some text from a named pipe in ruby. The writing is done
> in another (C++) program and I'd like to have Ruby display what is sent.
>
> I've looked at the IO.pipe function, but there seems to be no way to get
> a NAMED pipe.

Named pipes are opened and read or written as though they were files
(streams). Just open it by path and name.

> The two programs are running under Windows XP, btw.

Are you asking how to create the named pipe? That is an operating system
function, and frankly, I don't know if Windows supports them. The operating
system must support the idea of a named pipe, and if it doesn't, no named
pipe.

> Are named pipes even supported in Ruby?

As inputs and outputs, yes. This can be said of any language that opens and
reads/writes streams. But the pipe itself must be supported and created by
the OS.

> How can I read from one?

Open it like a file.

--
Paul Lutus
http://www.ara...

Günther Gruber

11/17/2006 1:57:00 PM

0

Paul Lutus wrote:
>> How can I read from one?
>
> Open it like a file.

Sounds simple, I'll try that out. Thanks!

--
Posted via http://www.ruby-....

Ara.T.Howard

11/17/2006 2:46:00 PM

0

Tom Pollard

11/20/2006 1:19:00 PM

0


On Nov 17, 2006, at 6:05 AM, Paul Lutus wrote:
> Named pipes are opened and read or written as though they were files
> (streams). Just open it by path and name.
>
>> The two programs are running under Windows XP, btw.
>
> Are you asking how to create the named pipe? That is an operating
> system
> function, and frankly, I don't know if Windows supports them. The
> operating
> system must support the idea of a named pipe, and if it doesn't, no
> named
> pipe.

Windows also has named pipes, but they behave somewhat differently
than Unix named pipes. I only have experience with them in C and
Perl programming, but I found that you can't do non-blocking reads on
a named pipe under Windows, and you can't open, close and reopen the
same named pipe in a program. Basically, to use a named pipe for
accepting messages under Windows, you probably need to spawn a
separate thread to listen to it.

If you're porting Unix software that uses named pipes to Windows, you
might be best off selecting a different IPC mechanism altogether,
such as sockets. In our porting efforts, we ended up writing a small
library that simulated Unix named pipes under Windows using shared
memory.

Tom