Python: Start new command prompt on Windows and wait for it finish/exit

前端 未结 5 1256
夕颜
夕颜 2020-11-28 11:23

I don\'t understand why it\'s so hard to do this on Windows.

I want to spawn a bunch of command prompt windows which will run other scripts. The reason I want this i

相关标签:
5条回答
  • 2020-11-28 11:39

    Upon reading your comment to my previous answer what you need is:

    os.system("start /wait cmd /c {command}")
    

    Keep the windows command reference always at hand!

    0 讨论(0)
  • 2020-11-28 11:43

    For me this seems to work
    os.system("cmd /k {command}")

    With /k cmd executes and then remain open
    With /c executes and close

    To open a new command window and then execute the command
    os.system("start cmd /k {command}")

    0 讨论(0)
  • 2020-11-28 11:52

    The accepted answer didn't work for me.
    To open on a new command prompt I had to use:

    os.system("start /B start cmd.exe @cmd /k mycommand...")
    
    0 讨论(0)
  • 2020-11-28 11:53

    You can pass /WAIT to the start command to make it wait for termination.

    0 讨论(0)
  • 2020-11-28 11:56

    How about

    os.system("cmd /c {command here}") 
    

    Or even

    os.system("{command here}")
    

    It is the start command the one that is launching a separate session instead of using the same one the python program is running on.

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