我正在使用 Unix 操作系统,我想知道如何在 Python 脚本中执行可从不同软件执行的命令。我在我的系统中安装了这个名为 HAL Tools 的软件,它有一个名为 maf2hal 的命令,带有两个参数,分别是输入和输出文件。命令的路径保存在我的 .bash_profile 中的 PATH 变量下。我同样从 UNIX 调用命令:
[root ~]$ maf2hal inputfile outputfile
Run Code Online (Sandbox Code Playgroud)
我想从 Python 脚本中调用此命令。我需要使用的语句或函数是什么。
1.使用os.popen()执行命令:
import os
os.popen("maf2hal inputfile outputfile")
Run Code Online (Sandbox Code Playgroud)
from subprocess import call
call("maf2hal inputfile outputfile", shell=True)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
92 次 |
| 最近记录: |