reading from named pipes

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

reading from named pipes

Chris Dawson
Hi there,

I'm trying to read from a named pipe.  I'm on Linux (Ubuntu 8.04).
  • I created the pipe using mkfifo
  • I can write to it, and when I cat the pipe within another terminal I see the output.
  • I've tried using various combinations of FileStream, OSProcess-ExternalPipe and OSProcess-AsyncFileReadStream. 
    • For example, I used this code:  pipe := OSPipe new. file := FileStream fileNamed: '/my/named/pipe'. pipe reader: file. foo := pipe upToEndOfFile. It just hangs when I do this.
Any suggestions?

Chris

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: reading from named pipes

John Foster-3
> Hi there,
>
> I'm trying to read from a named pipe.  I'm on Linux (Ubuntu 8.04).
>
>    - I created the pipe using mkfifo
>    - I can write to it, and when I cat the pipe within another terminal I
>    see the output.
>    - I've tried using various combinations of FileStream,
>    OSProcess-ExternalPipe and OSProcess-AsyncFileReadStream.
>    - For example, I used this code:
> pipe := OSPipe new.
> file := FileStream fileNamed: '/my/named/pipe'.
> pipe reader: file.
> foo := pipe upToEndOfFile.
>       It just hangs when I do this.
>
> Any suggestions?

Unix named pipes block until processes have opened each end of the pipe.
This is normal behaviour.  When you get the hung squeak, switch to another
term and try:

echo > /my/named/pipe
useless mindless text
^D

and  the string 'useless mindless text\n' should then be in foo.

John

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: reading from named pipes

David T. Lewis
On Fri, May 23, 2008 at 06:33:12AM +1000, [hidden email] wrote:

> > Hi there,
> >
> > I'm trying to read from a named pipe.  I'm on Linux (Ubuntu 8.04).
> >
> >    - I created the pipe using mkfifo
> >    - I can write to it, and when I cat the pipe within another terminal I
> >    see the output.
> >    - I've tried using various combinations of FileStream,
> >    OSProcess-ExternalPipe and OSProcess-AsyncFileReadStream.
> >    - For example, I used this code:
> > pipe := OSPipe new.
> > file := FileStream fileNamed: '/my/named/pipe'.
> > pipe reader: file.
> > foo := pipe upToEndOfFile.
> >       It just hangs when I do this.
> >
> > Any suggestions?
>
> Unix named pipes block until processes have opened each end of the pipe.
> This is normal behaviour.  When you get the hung squeak, switch to another
> term and try:
>
> echo > /my/named/pipe
> useless mindless text
> ^D
>
> and  the string 'useless mindless text\n' should then be in foo.

I would add that although you do not need OSProcess to use named pipes
(they are just "files" after all), you can avoid the problem of blocking
your Squeak VM as follows, assuming you have a name pipe called "PIPE":

  f := FileStream fileNamed: 'PIPE'.
  OSProcess accessor setNonBlocking: f fileID.

Now when you read from the pipe, you will get only the available data (or
nothing), and the VM will not block:

  f next: 100 ==> ''

Dave
 
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners