This question already has answers here:
Calling an external command from Python
(62个答案)
5年前关闭。
我正在使用Unix OS,我想知道如何执行可以从Python脚本中的其他软件执行的命令。
我已将此软件安装到名为HAL Tools的系统中,并且具有名为maf2hal的命令,该命令带有两个作为输入和输出文件的参数。命令的路径保存在我的.bash_profile中的PATH变量下。我同样从UNIX调用命令:
[root ~]$ maf2hal inputfile outputfile
我想从Python脚本调用此命令。我需要使用什么语句或函数。
python大神给出的解决方案
1.使用os.popen()执行命令:
import os
os.popen("maf2hal inputfile outputfile")
2. subprocess.call()
from subprocess import call
call("maf2hal inputfile outputfile", shell=True)