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

后端 未结 6 1091
既然无缘
既然无缘 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:11

    Similar to what @firsthand said, I've read on the wxPython-user forums that you "replace" the current running application, that would be "command.com" or "CMD.exe", with pyw.exe or pythonw.exe when you use something like the following:

    os.execl(sys.executable, *([sys.executable]+sys.argv))
    

    see another post

    Although I do not know how you would pipe io in this case.

    I believe one benefit of this approach is if you run your script multiple times your OS taskbar with not fill up with CMD icons. The other way if you have several CMD minimized in the taskbar and start closing them, it is impossible to tell which CMD goes with which pythonw script.

提交回复
热议问题