Echo console to a device (and vice-versa)?

Francis Avila francisgavila at yahoo.com
Sun Oct 5 16:24:08 EDT 2003


"Peter Otten" <__peter__ at web.de> wrote in message
news:bljgqr$995$06$1 at news.t-online.com...
> Francis Avila wrote:
>
> >         try:
> >             ttybuf = os.read(ttyfdout, 1)
> >         except OSError, err:
> >             if err == EAGAIN:
> >                 pass
> >         else:
> >             os.write(stdout, ttybuf)
>
> Well, admitting that I don't have any idea what you want to do, the above
> code silences *any* OSError, i. e.
>
> if err == EAGAIN:
>     pass
>
> is a NOOP. If you want to catch only EAGAIN, you might consider
>
> try:
>     ttybuf = os.read(ttyfdout, 1)
> except OSError, err:
>     if err != EAGAIN:
>         raise
> else:
>     os.write(stdout, ttybuf)
>
> instead.
>
> Peter


That's true, thanks. I was thinking a bit sloppily, catching EAGAIN as
though it were itself an exception.  However, it doesn't effect functioning
unless some other fatal exception pops up.

The problem was simply that my tty wasn't raw enough.  It wasn't sufficient
to make the tty raw from the shell (using, in this case, 'stty raw pass8').
Calling tty.setraw on each of the four fd's solved the problem without
incident, and the code works exactly as expected.

Of course, now there are no excape characters, so I can't even ^C to exit,
but this is all resolvable.
--
Francis Avila





More information about the Python-list mailing list