Python:如何执行外部程序 [英] Python: How to execute an external program
本文介绍了Python:如何执行外部程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在我的程序中执行程序而不阻塞直到执行的程序完成?
How do I execute a program from within my program without blocking until the executed program finishes?
我试过了:
os.system()
但它会停止我的程序,直到执行的程序停止/关闭.有没有办法让我的程序在外部程序执行后继续运行?
But it stops my program till the executed program is stopped/closed. Is there a way to allow my program to keep running after the execution of the external program?
推荐答案
考虑使用 subprocess 模块.
- Python 2:http://docs.python.org/2/library/subprocess.html
- Python 3:http://docs.python.org/3/library/subprocess.html
subprocess 生成一个新进程,您的外部应用程序在其中运行.当其他应用程序运行时,您的应用程序会继续执行.
subprocess spawns a new process in which your external application is run. Your application continues execution while the other application runs.
这篇关于Python:如何执行外部程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文