Clearing a DOS terminal in a script

John Machin sjmachin at lexicon.net
Thu Dec 13 13:56:56 EST 2007


On Dec 14, 3:48 am, Stephen_B <step... at theboulets.net> wrote:
> This doesn't seem to work in a dos terminal at the start of a script:
>
> from os import popen
> print popen('clear').read()
>
> Any idea why not? Thanks.

Maybe you are using a different "dos terminal". What is "clear"?

C:\junk>clear
'clear' is not recognized as an internal or external command,
operable program or batch file.

C:\junk>ver

Microsoft Windows XP [Version 5.1.2600]

C:\junk>help cls
Clears the screen.

CLS

C:\junk>

The following works for me:

<code>
import os
os.system('cls')
print 'Howzat?'
</code>

To use ANSI escape sequences with the "real" MS-DOS, one needed a
console device driver (ANSI.SYS was supplied) and had to invoke it in
the CONFIG.SYS file; presumably you can find out how to set this up in
a Windows Command Prompt window, but it doesn't seem to be worth the
bother if all you want to do is clear the window.

HTH,
John



More information about the Python-list mailing list