zsh-users
 help / color / mirror / code / Atom feed
* Re: Inter-Shell communication ?
@ 2001-03-08 10:27 Sven Wischnowsky
  2001-03-25 19:03 ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: Sven Wischnowsky @ 2001-03-08 10:27 UTC (permalink / raw)
  To: zsh-users


jarausch@igpm.rwth-aachen.de wrote:

> Hi,
> 
> is there an elegant technique for one zshell waiting
> for a different zshell (i.e. running in a different xterm)
> to complete?
> (better than e.g. periodically checking for a file that
> the second zshell touches at completion)
> 
> Thanks for your hint,

I can only think of named pipes (`mknod foo p') with `read var <foo' and
`print go >foo'.

If the pid of the waiting shell is known, one can also use one of the
USR-signals. Or start a endlessly running process in the wait-shell,
wait for it and kill it from the other shell.


We really need that generic socket module ;-)

Bye
 Sven


--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Inter-Shell communication ?
  2001-03-08 10:27 Inter-Shell communication ? Sven Wischnowsky
@ 2001-03-25 19:03 ` Bart Schaefer
  0 siblings, 0 replies; 3+ messages in thread
From: Bart Schaefer @ 2001-03-25 19:03 UTC (permalink / raw)
  To: zsh-users

On Mar 8, 11:27am, Sven Wischnowsky wrote:
} 
} jarausch@igpm.rwth-aachen.de 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   


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Inter-Shell communication ?
@ 2001-03-08  9:12 jarausch
  0 siblings, 0 replies; 3+ messages in thread
From: jarausch @ 2001-03-08  9:12 UTC (permalink / raw)
  To: zsh-users

Hi,

is there an elegant technique for one zshell waiting
for a different zshell (i.e. running in a different xterm)
to complete?
(better than e.g. periodically checking for a file that
the second zshell touches at completion)

Thanks for your hint,

Helmut Jarausch

Lehrstuhl fuer Numerische Mathematik
Institute of Technology, RWTH Aachen
D 52056 Aachen, Germany



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2001-03-25 19:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-03-08 10:27 Inter-Shell communication ? Sven Wischnowsky
2001-03-25 19:03 ` Bart Schaefer
  -- strict thread matches above, loose matches on Subject: below --
2001-03-08  9:12 jarausch

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).