Python的subprocess模块
尝试在Python中运行可执行文件,网上给出的解决方案是:
顿时豁然开朗,如果要运行C盘下的文件名为“Magic Kit.exe”的程序,只需:
import os
os.system("此处填程序路径")
我要运行的程序文件名中有空格,因此果断失败了,查看了一下帮助文档,果然,在现在版本的Python中有个取代os.system的模块:subprocess!
帮助文档中是这样写的:
NAME
subprocess - subprocess - Subprocesses with accessible I/O streams
FILE
c:\python27\lib\subprocess.py
DESCRIPTION
This module allows you to spawn processes, connect to their
input/output/error pipes, and obtain their return codes. This module
intends to replace several other, older modules and functions, like:
os.system
os.spawn*
os.popen*顿时豁然开朗,如果要运行C盘下的文件名为“Magic Kit.exe”的程序,只需:
import subprocess
subprocess.Popen("c:/Magic Kit.exe")就能顺利运行啦!
或者:
subprocess.Popen("notepad.exe c:/Magic Kit.exe")可以指定使用记事本运行该程序~~
作者:Noah Zhang
本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
posted on 2014-07-25 17:35 Noah.Zhang 阅读(460) 评论(0) 收藏 举报
浙公网安备 33010602011771号