简体   繁体   English

使用python os或子进程模块在后台运行命令行程序

[英]running command line programs in background using python os or subprocess module

I am trying to run a command using os or subproccess module in python. 我试图在os使用ossubproccess模块运行命令。 the command prompt window briefly flickers before terminating. 在终止之前,命令提示符窗口会短暂闪烁。 Is there a way of eliminating that popping up of command prompt window..? 有没有一种方法可以消除弹出的命令提示符窗口。

For example: 例如:

os.system("ffmpeg -i output.wav output.flac")

Is there a way I can run this in the background so that user may not notice this..? 有没有一种方法可以让我在后台运行此程序,以使用户可能不会注意到此..?

I am running windows 7 with python 2.7. 我正在使用python 2.7运行Windows 7。

of coarse ... you even tagged it with the module you would use ... 的粗略...您甚至用要使用的模块对其进行了标记...

subproccess.Popen("ffmpeg -i output.wav output.flac".split(),shell=True).communicate()

should do it ... 应该做...

The easiest thing would be to try to take advantage of the subproccess modules partial support for the STARTUPINFO structure. 最简单的方法是尝试利用子subproccess模块对STARTUPINFO结构的部分支持。 Something like this: 像这样:

info = subprocess.STARTUP_INFO()
info.dwFlags = subprocess.STARTF_USESTDHANDLES | subprocess.STARTF_USESHOWWINDOW
info.wShowWindow = subprocess.SW_HIDE

process = subprocess.Popen("ffmpeg -i output.wav output.flac", startupinfo=info)
process.wait()

def asyncRun(command): os.system(command)

t = Thread(target=asyncRun, args=('ping 127.0.0.1 -s 271',)) t.start()

适用于Windows 10 + EMET + 2.7

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM