Re: Setting win32 console title from Python
- From: Duncan Booth <duncan.booth@xxxxxxxxxxxxxxx>
- Date: 28 Apr 2005 12:20:07 GMT
runes wrote:
> I'm trying to set the title of the console window (CMD.EXE) in Windows.
> I want it set to the basename of the current directory and it should
> stay after the script has finished.
>
> Any ideas?
>
I don't think you can do that.
Whenever you start an application from the command prompt the title is
modified by appending a dash and the name of the program you started. When
the application terminates the title is reset (to remove the name of the
running program). So any change to the title will only last until the next
time CMD.EXE prompts for input. The exception is that any title set using
the TITLE command becomes the reset title for that command prompt.
I can think of only one way round this, which is to run your python program
from a batch file and find some way to pass the desired title back to the
batch file where you can set it with the TITLE command. For example, you
could write the title to a temporary file, or if your program doesn't
produce much other output print it to stdout and parse the program output
using a for command:
e.g. This sets the title to the current time:
C:\>FOR /F "tokens=*" %i in (
More? 'python -c "from time import *; print asctime(localtime())"'
More? ) DO @TITLE %i
C:\>
Obvious notes: In a batch file you would double the % characters, and you
don't type C:\> or More? as these are the prompts from CMD.EXE. Also this
won't work on really old versions of CMD.EXE or with COMMAND.COM.
.
- Follow-Ups:
- Re: Setting win32 console title from Python
- From: runes
- Re: Setting win32 console title from Python
- References:
- Setting win32 console title from Python
- From: runes
- Setting win32 console title from Python
- Prev by Date: Getting a list of classes in the current module/auto introspection
- Next by Date: anonymous function objects?
- Previous by thread: Setting win32 console title from Python
- Next by thread: Re: Setting win32 console title from Python
- Index(es):
Relevant Pages
|