CRLF when doing os.system("ls -l") while using curses !!!

Piet van Oostrum piet at cs.uu.nl
Fri May 29 18:35:38 EDT 2009


>>>>> lkennedy5 at gmail.com (l) wrote:

>l> Here is the code and as you can see for yourself, the output is not
>l> coming out on the screen with CRLF like it should.  How do I fix this?

Don't use curses.

Curses puts the terminal in raw mode (more or less) which doesn't
translate the newline character into CRLF. If you use curses you are
supposed to do all output through curses. But the os.system goes
directly to the screen, outside of curses (because it is another
process).
You could catch the output of ls -l with a PIPE and then write the
output to the curses screen with addstr. But a curses screen has a
limited length, whereas your ls -l output may be larger so then you must
implement some form of scrolling.

>l> import curses, os
>l> screen = curses.initscr()
>l> os.system("ls -l")
>l> curses.endwin()

-- 
Piet van Oostrum <piet at cs.uu.nl>
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: piet at vanoostrum.org



More information about the Python-list mailing list