-2

我需要编写一个 python 脚本来自动化一些重复的 Linux 命令。(使用 mac 的人给我的)命令主要是 mkdir 和 htk 语音识别工具包命令。我需要在 cygwin 上执行这些命令。我尝试搜索有关如何执行此操作的教程,但认为我还没有找到合适的教程。我对python很陌生。

4

1 回答 1

2

当我使用 python 作为 shell 替换时,我的导入部分通常如下所示:

from os import mkdir, chdir
from shutil import move, copy, rmtree, copytree
from subprocess import call

这使我能够移动和复制文件和目录以及创建新目录和删除目录。如果要在 shell 上调用程序而不是使用 python 函数,call请从subprocess模块中使用。

# To run the program foo that takes an option and two arguments
# Equivalent to "foo -d bar baz" directly in the shell
call(['foo', '-d', 'bar', 'baz'])

你会使用callhtk 的东西。

于 2013-03-29T02:31:58.243 回答