Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Tesing a fifo without opening it?
- X-seq: zsh-users 15396
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: Tesing a fifo without opening it?
- Date: Sun, 12 Sep 2010 21:20:39 -0700
- In-reply-to: <20100912234331.GA2497@xxxxxx>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <20100910063544.45240@xxxxxxx> <20100910113632.GA4692@xxxxxxxx> <20100910123616.114190@xxxxxxx> <100912120223.ZM17365@xxxxxxxxxxxxxxxxxxxxxx> <20100912234331.GA2497@xxxxxx>
On Sep 13, 1:43am, Dominik Vogt wrote:
} On Sun, Sep 12, 2010 at 12:02:23PM -0700, Bart Schaefer wrote:
} > On Sep 10, 8:35am, Dominik Vogt wrote:
} > } ---- sub script
} > } 01 read REQUEST < "$1"
} > } 02 echo answer > "$2"
} >
} > Of course with the coproc, these are stdin/stdout so you don't need
} > $1 and $2 and redirections. If for some reason you're counting on
} > the script to have inherited the parent's stdin/out, you can't use
} > coproc.
}
} Actually, the script may exec a c-program that can not use stdin
} and stdout for the command channels. Is it possible to have the
} coproc use separate descriptors for stdio and the coproc pipes?
Ah, I wondered. First let me note that c-programs, unless specifically
designed to, e.g., use non-blocking I/O, are highly likely to encounter
the deadlock situation I described previously. The standard set of
text utilities (cat, sed, et al.) are very difficult to use in these
circumstances.
That said ... the coprocess when first started will always have its
stdin and stdout connected to the pipes. However, you can use exec
with redirection to juggle that any way you wish. E.g.,
# Copy shell stdio
exec {s_in}<&0 {s_out}>&1
# Start coprocess
coproc {
# Save coprocess stdio
exec {c_in}<&0 {c_out}>&1
# Reconnect to shell stdio
exec <&$s_in >&$s_out
# Now do the original work
read -u $c_in command
eval "$command"
print -u $c_out "all finished"
}
# Try it
print -p 'echo IN COPROCESS' ; read -E -p
You could do all four redirections in a single "exec" but it's a bit
more obvious what's happening if you use two.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author