zsh-users
 help / color / mirror / code / Atom feed
From: "Bart Schaefer" <schaefer@candle.brasslantern.com>
To: zsh-users@sunsite.dk
Subject: Re: Inter-Shell communication ?
Date: Sun, 25 Mar 2001 19:03:20 +0000	[thread overview]
Message-ID: <1010325190320.ZM10531@candle.brasslantern.com> (raw)
In-Reply-To: <200103081027.LAA09315@beta.informatik.hu-berlin.de>

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   


  reply	other threads:[~2001-03-25 19:04 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-03-08 10:27 Sven Wischnowsky
2001-03-25 19:03 ` Bart Schaefer [this message]
  -- strict thread matches above, loose matches on Subject: below --
2001-03-08  9:12 jarausch

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1010325190320.ZM10531@candle.brasslantern.com \
    --to=schaefer@candle.brasslantern.com \
    --cc=zsh-users@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).