Opening a Python thread in a new console window

后端 未结 3 1477
终归单人心
终归单人心 2020-12-01 22:18

I am trying to make a program that will launch both a view window (console) and a command line. In the view window, it would show constant updates, while th

3条回答
  •  既然无缘
    2020-12-01 22:21

    UPDATED ANSWER:

    import subprocess
    command = "dir"
    subprocess.run(["cmd.exe", "/c", "start", f"{command}"], timeout=15)
    

    "cmd.exe" - if using Windows, Windows ONLY recognizes double quotes.
    "/c" - says 'send the Return' after we send the 'dir'(for example) string.
    "start" - says open new console window...even if debugging in Pycharm :)
    f"command" - I use f-strings to send assemble strings Python3.6+
    (timeout optional)

提交回复
热议问题