[英]Stop invoking of new Shell/cmd prompt , python
i have a python script which should invoke a .exe file to get some result. 我有一个python脚本,应该调用.exe文件以获得一些结果。 That .exe file is invoking a new windows command prompt(shell) .
该.exe文件正在调用新的Windows命令提示符(shell)。 i dont need any output from the .exe file.
我不需要.exe文件的任何输出。
i 'm using os.system('segwin.exe args') in my script where segwin is an executable. 我在segwin是可执行文件的脚本中使用os.system('segwin.exe args')。
now my question is : i need to stop invoking cmd prompt 现在我的问题是:我需要停止调用cmd提示符
kudos to all 所有人的荣誉
sag 下垂
Try this (untested): 试试这个(未试用):
import subprocess
CREATE_NO_WINDOW = 0x08000000
args = [...]
subprocess.check_call(["segwin.exe"] + args, creationflags=CREATE_NO_WINDOW)
Note that check_call
checks the return code of the launched subprocess and raises an exception if it's nonzero. 请注意,
check_call
检查已启动子check_call
的返回码,如果非零,则引发异常。 If you don't want that, use call
instead. 如果您不想这样做,请改用
call
。
In general, avoid os.system()
and use the subprocess
module whenever possible. 通常,请避免使用
os.system()
并尽可能使用subprocess
模块。 os.system()
always starts a shell, which is nonportable unnecessary on most cases. os.system()
总是启动一个shell,在大多数情况下这是不可移植的不必要的。
This is actually specific to Windows. 这实际上是Windows特有的。 Windows has decided that
segwin.exe
is a console-based application (uses the Console subsystem from the Windows C interface). Windows已确定
segwin.exe
是基于控制台的应用程序(使用Windows C接口中的Console子系统)。
I know how to invoke an prompt for apps that don't necessarily want one, but not the reverse, you could try using this , or this . 我知道如何为不一定想要一个但不是相反的应用程序调用提示,您可以尝试使用this或this 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.