Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Tesing a fifo without opening it?



2010-09-10 08:35:44 +0200, Dominik Vogt:
[...]
> 05   if read -t REQUEST < "$1"; then
[...]
> Now, the problem is that input redirection in line 5 blocks
> until the main script also opens the fifo.  So the -t flag of
> read does not "work" here (because read is not even executed
> until the fifo can be opened).  I want to check if data is
> available in the fifo without blocking, but I can't find a way
> around blocking in the input redirection.
[...]

On Linux (at least, though the behavior is not clearly defined
by POSIX)

read -t REQUEST <> "$1"

should work.

Otherwise, other approaches: open with O_NONBLOCK (though you'd
need to do it in something else as I don't think zsh has an
interface to open with O_NONBLOCK).

Or you could do

: > "$1" & read...

though it would have other side effects.

-- 
Stephane



Messages sorted by: Reverse Date, Date, Thread, Author