3 # vi:set sts=2 sw=2 ai:
9 # coprocess - Start, control, and end coprocesses.
13 while (( $# > 0 )) ; do
22 if [ "$1" = "-SIGPIPE" ] ; then
23 # Only print message in an interactive shell
39 local fifo
="/var/tmp/coprocess.$$.$RANDOM"
42 if (( $# > 0 )) ; then
46 mkfifo "$fifo.in" ||
return $?
47 mkfifo "$fifo.out" ||
{
53 ( "$@" <$fifo.
in >$fifo.out
; rm -f "$fifo.in" "$fifo.out" ) &
55 exec 61>$fifo.
in 62<$fifo.out
60 # coprocess print - write to the coprocess
64 local old_trap
=$
(trap -p SIGPIPE
)
65 trap 'coprocess close -SIGPIPE' SIGPIPE
66 if [ $# -eq 1 ] && [ "$1" = "--stdin" ] ; then
77 # coprocess read - read from the coprocess
81 local old_trap
=$
(trap -p SIGPIPE
)
82 trap '_coprocess_close -SIGPIPE' SIGPIPE
83 builtin read "$@" <&62
89 s|st|sta|stat|statu|status
)
90 if [ -z "$coprocess_pid" ] ; then
91 echo 'no active coprocess'
94 echo " coprocess is active [$coprocess_pid]"