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

Re: Looks like "zpty -r" is adding 0x0d characters...

    Hi Bart :)

 * Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> dixit:
> A pty opened with zpty is just like any other tty device, i.e., it
> has various settings that can be viewed and changed with "stty".

    I know, but...

> The values of those settings do not necessarily correspond to those
> of the controlling tty of the process.

    ...here I assumed that the settings were not inherited, of
course, but I assumed that, by default, things like "echo" or
"oeche", "echok", etc. were controlled by the "-e" option to "zpty",
and things like onlcr were deactivated (any translation, for that
matter) since the pty is treated like a file more than like a tty.

    My fault O:)

> For example, try:
>     zpty settings stty -a
>     zpty -r settings
> You'll probably find "onlcr" in that output, which means "for output,
> translate newline to carriage return-newline".

    onclr is on in the pty and in my tty, and I need it in my tty,
otherwise I don't get the carriage return :? In fact, my "stty sane"
command does exactly that.

    Of course, Linux virtual terminal "eats" the carriage returns and
if I redirect any printed output to a file the \n characters are not
translated. With the pty I'm getting to a file exactly the same chars
that would go to the terminal, so the \n chars ARE translated.

> If you don't want this to happen, the program that zpty runs on the
> pseudo-terminal needs to do the equivalent of "stty -onlcr".

    That's a bit difficult, because the command I'm running doesn't
deal with the tty in any way, it just prints output (but for some
errors it goes interactive, that's why I need zpty in my wrapper). I
find easier to do a simple substitution on the text:

    zpty -r settings buffer "pattern..."

    But thanks A LOT for the hint, I just didn't consider that the
problem could be the onlcr setting of the terminal :))

    I think that terminal settings for "zpty" would be a good idea,
but I'm sure that it will cause portability problems, true? :( In C
you can open a tty and set modes on it afterwards, but for a shell
script you can use ${//} for any translation, and things like echo
are controlled by a flag.

    Thanks, Bart :)))))) You saved me a bid headache :)

    BTW, the program I'm controlling with zpty is "cdda2wav". This
program prints a string (without a newline) and waits for a keypress
if it doesn't find a CD on the unit, so I need zpty to get its
output. Otherwise I would use just "output=`cdda2wav`". This is the
code snippet for the control:

zpty cdda2wav cdda2wav -v toc,sectors -J -H

while true
    zpty -r cdda2wav line "*(CD-Extra: *"$'\n'"|press enter)"
    if [[ "$line" == *"load cdrom"* ]]
        # Much more pretty than the default string...
        print -n "Please load an audio CD and press <Enter>"
        read -k 1 line
        zpty -w cdda2wav "$line"
        print -- "$line" > log
        # Here I must do the translation to get rid of \C-M

zpty -d cdda2wav

    I was already using a substitution, but I couldn't think about
why it was necessary (I added it because I found the problem, but
later I noticed that it shouldn't happen).

    Raúl Núñez de Arenas Coronado

Linux Registered User 88736 | http://www.dervishd.net
http://www.pleyades.net & http://www.gotesdelluna.net
It's my PC and I'll cry if I want to...

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