How to avoid console window with .pyw file containing os.system call?

后端 未结 6 1083
既然无缘
既然无缘 2020-11-29 08:59

If I save my code files as .pyw, no console window appears - which is what I want - but if the code includes a call to os.system, I still get a pes

6条回答
  •  情深已故
    2020-11-29 09:27

    The solution that Piotr describes is actually not as complicated as it may sound. Here is an example where a startupinfo is passed to a check_call invocation to suppress the console window:

    startupinfo = subprocess.STARTUPINFO()
    startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
    
    subprocess.check_call(cmd, startupinfo=startupinfo)
    

    Since the convenience functions call, check_call, and check_output forward their **kwargs to the Popen constructor, it is not required to use Popen directly.

提交回复
热议问题