Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Running commands in a zpty worker
On Aug 11, 1:53am, Mathias Fredriksson wrote:
}
} I went back to my original use case where I'm running commands in a
} zpty worker and notifying the original zsh pid that the work is done
} (previously through WINCH, now tested with USR1).
Incidentally you might try using ZLE handler functions for this instead
of signals. You'd need a FIFO for the zpty command to write to and the
ZLE handler to listen on.
Which is really kind of silly given that there's already a descriptor.
With this patch you can do e.g.
typeset -A ptys
watcher() { local line; zpty -r $ptys[$1] line; etc with $line }
zpty firstPTY some command ...
ptys[$REPLY]=firstPTY
zle -F $REPLY watcher
Just be careful to remove the handler before the slave side of the pty
is closed (e.g., worker exits) or you may end up with a runaway handler.
diff --git a/Doc/Zsh/mod_zpty.yo b/Doc/Zsh/mod_zpty.yo
index 340f983..44b375a 100644
--- a/Doc/Zsh/mod_zpty.yo
+++ b/Doc/Zsh/mod_zpty.yo
@@ -18,6 +18,15 @@ characters are echoed.
With the tt(-b) option, input to and output from the pseudo-terminal are
made non-blocking.
+
+The shell parameter tt(REPLY) is set to the file descriptor assigned to
+the master side of the pseudo-terminal. This allows the terminal to be
+monitored with ZLE descriptor handlers (see ifzman(zmanref(zshzle))\
+ifnzman(noderef(Zle Builtins))) or manipulated with tt(sysread) and
+tt(syswrite) (see ifzman(THE ZSH/SYSTEM MODULE in zmanref(zshmodules))\
+ifnzman(noderef(The zsh/system Module))). em(Warning): Use of tt(sysread)
+and tt(syswrite) is em(not) recommended, use tt(zpty -r) and tt(zpty -w)
+unless you know exactly what you are doing.
)
item(tt(zpty) tt(-d) [ var(name) ... ])(
The second form, with the tt(-d) option, is used to delete commands
diff --git a/Src/Modules/zpty.c b/Src/Modules/zpty.c
index 7b6130c..12e42b5 100644
--- a/Src/Modules/zpty.c
+++ b/Src/Modules/zpty.c
@@ -463,6 +463,8 @@ newptycmd(char *nam, char *pname, char **args, int echo, int nblock)
#endif
errno == EINTR));
+ setiparam("REPLY", master);
+
return 0;
}
Messages sorted by:
Reverse Date,
Date,
Thread,
Author