Set Windows command-line terminal title in Python

前端 未结 9 1920
攒了一身酷
攒了一身酷 2020-12-01 00:52

I\'m running several instances of a certain Python script on a Windows machine, each from a different directory and using a separate shell windows. Unfortunately Windows giv

相关标签:
9条回答
  • 2020-12-01 01:34

    If starting the Idle-shell is an option instead of the cmd shell:

    idle.py [-c command] [-d] [-e] [-s] [-t title] [arg] ...
    
    -c command  run this command
    -d          enable debugger
    -e          edit mode; arguments are files to be edited
    -s          run $IDLESTARTUP or $PYTHONSTARTUP first
    -t title    set title of shell window
    
    0 讨论(0)
  • 2020-12-01 01:40

    Comparison of the posted system() & windll-based methods

    tying to add a small quantitative comparison of latency overheads associated with two of the posted methods:

    |>>> from zmq import Stopwatch
    |>>> aSWX = Stopwatch()
    
    |>>> from os import system
    |>>> aSWX.start();system( 'TITLE os_SHELL_CMD_TITLE_TXT');aSWX.stop()  15149L [us]
    |>>> aSWX.start();system( 'TITLE os_SHELL_CMD_TITLE_TXT');aSWX.stop()  15347L [us]
    |>>> aSWX.start();system( 'TITLE os_SHELL_CMD_TITLE_TXT');aSWX.stop()  15000L [us]
    |>>> aSWX.start();system( 'TITLE os_SHELL_CMD_TITLE_TXT');aSWX.stop()  14674L [us]
    |>>> aSWX.start();system( 'TITLE os_SHELL_CMD_TITLE_TXT');aSWX.stop()  14774L [us]
    |>>> aSWX.start();system( 'TITLE os_SHELL_CMD_TITLE_TXT');aSWX.stop()  14551L [us]
    |>>> aSWX.start();system( 'TITLE os_SHELL_CMD_TITLE_TXT');aSWX.stop()  14633L [us]
    |>>> aSWX.start();system( 'TITLE os_SHELL_CMD_TITLE_TXT');aSWX.stop()  15202L [us]
    |>>> aSWX.start();system( 'TITLE os_SHELL_CMD_TITLE_TXT');aSWX.stop()  14889L [us]
    
    |>>> from ctypes import windll
    |>>> aSWX.start();windll.kernel32.SetConsoleTitleA('DLL');aSWX.stop()   5767L [us]
    |>>> aSWX.start();windll.kernel32.SetConsoleTitleA('DLL');aSWX.stop()    643L [us]
    |>>> aSWX.start();windll.kernel32.SetConsoleTitleA('DLL');aSWX.stop()    573L [us]
    |>>> aSWX.start();windll.kernel32.SetConsoleTitleA('DLL');aSWX.stop()    749L [us]
    |>>> aSWX.start();windll.kernel32.SetConsoleTitleA('DLL');aSWX.stop()    689L [us]
    |>>> aSWX.start();windll.kernel32.SetConsoleTitleA('DLL');aSWX.stop()    651L [us]
    

    In cases, where one might spend about a half of millisecond ( but not some tens of that ) the windll.kernel32 method seems promising and may serve better for an alternative display of a WatchDOG / StateVARs / ProgressLOG / auto-self-diagnostic messages, being efficiently displayed in a soft real-time need, during long running processes.

    0 讨论(0)
  • 2020-12-01 01:42

    On Windows, a simple console command will suffice:

    from os import system
    system("title "+myCoolTitle)
    

    Nice & easy.

    0 讨论(0)
提交回复
热议问题