Named PIPEs

Anything QL Software or Programming Related.
Gold Card
Posts: 305
Joined: Tue Dec 17, 2013 1:17 pm

Named PIPEs

Postby Martin_Head » Wed Dec 20, 2017 11:14 am

Is there a way to test if a named PIPE in SMSQ/E is empty? EOF does not seem to work.

Also how do you empty a PIPE, or ensure it is empty, If there is nothing in it you want. Closing and re opening does not seem to empty it. The only idea I have had is to run a loop reading it.

If #4 is the open pipe

REP loop
IF a$="" THEN EXIT loop
END REP loop

User avatar
QL Wafer Drive
Posts: 1378
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

Re: Named PIPEs

Postby tofro » Wed Dec 20, 2017 12:40 pm


EOF or EOFW on a pipe actually indicate EOF only when the other end of the pipe has been closed.

In unexpanded S*Basic, using INKEY$ in a loop (albeit with a small timeout) seems to be the only way to do what you want. (I'm assuming you want a non-blocking read).

Tiny toolkit has a function PEND that exactly does what you want - returning 1 if there's nothing to read or 0 if there is something (without blocking).

DIY toolkit issue "P" has a function Q_COUNT% that returns the number of bytes available in a pipe

Pipes are one of the device types that could actually benefit a lot from a "read from channel in a buffer as much as is there until buffer full and return #of bytes read" - Function like fread() in C, which is unfortunately not implemented in S*BASIC. This would be a direct call to IO.FBYTES

With regards to emptying a pipe I see no other way than to do INKEY$ in a loop.


Gold Card
Posts: 305
Joined: Tue Dec 17, 2013 1:17 pm

Re: Named PIPEs

Postby Martin_Head » Thu Dec 21, 2017 10:30 am

Thanks for that.

I am running a loop, where I need the pipe to be empty at the start of each loop. So I think I will just do the small INKEY$ loop at the start of each main loop.

RWAP Master
Posts: 2461
Joined: Sun Nov 28, 2010 4:51 pm
Location: Stone, United Kingdom

Re: Named PIPEs

Postby RWAP » Thu Dec 21, 2017 11:19 am

I just used to pass a string to signify the end of data - eg *!PIPE_END!*

Return to “Software & Programming”

Who is online

Users browsing this forum: No registered users and 4 guests