Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Inter-Shell communication ?
- X-seq: zsh-users 3743
- From: "Bart Schaefer" <schaefer@xxxxxxxxxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: Inter-Shell communication ?
- Date: Sun, 25 Mar 2001 19:03:20 +0000
- In-reply-to: <200103081027.LAA09315@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <200103081027.LAA09315@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>
On Mar 8, 11:27am, Sven Wischnowsky wrote:
}
} jarausch@xxxxxxxxxxxxxxxxxxx wrote:
}
} > is there an elegant technique for one zshell waiting
} > for a different zshell (i.e. running in a different xterm)
} > to complete?
I take it that for some reason you can't simply start the second xterm
from the first shell and wait for the xterm process to exit?
} I can only think of named pipes (`mknod foo p') with `read var <foo' and
} `print go >foo'.
}
} We really need that generic socket module ;-)
The zpty module can be used for this, if you have zsh-3.1.9 or later.
(Some of you may recognize bits of this from my "zplitty" posting on
zsh-workers.)
---- 8< ---- snip ---- 8< ----
# Load the module
zmodload -i zsh/zpty || return
# Utility functions
zttywait () {
stty onlret -ocrnl -onlcr # May need to adjust this for your OS
tty
read -e
}
zttyget() {
setopt localoptions extendedglob noshwordsplit
zpty $1 zttywait
zpty -r $1 $1
: ${(P)1::=${(P)1%%[[:space:]]#}}
}
# Set up the pty -- this happens in the shell that will do the waiting
zttyget WAITPTY
# Now the parameter $WAITPTY has the name of the device from which the
# waiting zsh will read. How you propagate this name to the waited-for
# zsh is up to you. Perhaps write it to a file that's read into a new
# zsh from .zshenv?
# Now we wait.
zpty -r WAITPTY message
# When that wakes up, the other shell has finished.
print -u2 Shell exited: $message
# You can either delete this now, or keep using it for other exchanges.
zpty -d WAITPTY
---- 8< ---- snip ---- 8< ----
# This part happens in the second shell, that is to be waited-for. This
# assumes that both shells are owned by the same user so they will both
# have write permission on the slave-side of the pty.
TRAPEXIT () { print "All finished here." > $WAITPTY }
# That's it.
---- 8< ---- snip ---- 8< ----
It is possible for the second shell to die without executing the trap, if
it crashes or is hit with "kill -9"; in that case the waiting shell will
have to be woken up with a ctrl-C.
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net
Messages sorted by:
Reverse Date,
Date,
Thread,
Author