Re: Setting win32 console title from Python



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.
.



Relevant Pages

  • Re: How do I launch MS-DOS prompt to execute a batch file from within Excel worksheet with /VBA?
    ... You've asked for a command prompt from VBA. ... that in order to run your batch file. ...
    (microsoft.public.excel)
  • Re: Batch File Problem
    ... > access rights were set via Security and tested using Windows Explorer. ... > batch file is using xcopy and the manual copy used copy. ... There is no difference between running a command from the ... Command Prompt or running it inside a batch file. ...
    (microsoft.public.windowsxp.general)
  • Re: Batch File Problem
    ... >> batch file is using xcopy and the manual copy used copy. ... >There is no difference between running a command from the ... >Command Prompt or running it inside a batch file. ...
    (microsoft.public.windowsxp.general)
  • Re: Sophisticated(!) copying in DOS
    ... Open NOTEPAD and put in the contents. ... >> in at the command prompt - and no matter what I do, ... >> either works or it doesn't, and then the batch file closes. ...
    (microsoft.public.windowsxp.general)
  • Re: visual C++
    ... Which command should I use. ... compiling on console window. ... your Start menu to get a command prompt that's properly configured ... This will compile and link the program, ...
    (microsoft.public.vc.language)