Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Is this correct? Redirecting stdin/stout to implement a gdb-like "set inferior tty" in zshdb

On Tue, 9 Dec 2008 06:27:48 -0500
"Rocky Bernstein" <rocky.bernstein@xxxxxxxxx> wrote:
> Recently I needed to debug a GNU autoconf configure script which seems to do
> funky things with stdin and stdout. I realized that the shell debuggers
> really should have the equivalent of gdb's "set inferior tty" (
> http://www.mcs.vuw.ac.nz/cgi-bin/info2www?(gdb)Input/Output)
> Something along the lines of the below is what I came up with. But is this
> correct? $1 of course supposed to be the tty like say /dev/pts/1 on a
> GNU/Linuxy box.  When I tried it with the tty of another terminal, I'm
> getting output to the terminal but not input. I'm not sure it even makes
> sense to try to mug the input from another terminal or whether two processes
> (not even parent related) can read from the same input.
> #!/usr/local/bin/zsh
> typeset line
> exec 7<&0 </dev/null 6>&1  # Line taken from an autoconf "configure" script.
> #...
> exec {_Dbg_fdi} <> $1
> while : ; do
>   vared -e -h -p "foo> " line <&${_Dbg_fdi} || break
>   builtin print -- "$line" >&${_Dbg_fdi}
>   line=''
> done
> echo "That's all folks! (${_Dbg_fdi})"
> Does zsh have <> like ksh does? It wasn't rejected, so I assume it does.

That should indeed make the shell do what you expect, but I'm not clear
what you're supposed to be able to do with another terminal either, so it
doesn't entirely surprise me if it doesn't work.  It seem to work run as a
script running on /dev/tty (which as far as the non-interactive shell
running the script is concerned is just another file, no different from any
other terminal---the difference is down in the OS).

The only oddity was I didn't get history (the -h option to vared seemed to
do nothing), but I've forgotten whether I'm supposed to or not in this

Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070

Messages sorted by: Reverse Date, Date, Thread, Author