python - Python:subprocess.call错误“找不到命令”

标签 python shell subprocess

我正在尝试像这样在python脚本中运行命令:

subprocess.call("ghdl -a --ieee=synopsys -fexplicit " + testBenchFile + " >> a_log.txt", shell = True)


使用“ testBenchFile是字符串,但是会引发”找不到命令”错误。

我究竟做错了什么?

最佳答案

更改:

subprocess.call("ghdl -a --ieee=synopsys -fexplicit " + testBenchFile + " >> a_log.txt", shell = True)


至:

subprocess.call(["ghdl", "-a", "--ieee=synopsys", "-fexplicit", testBenchFile, ">>", "a_log.txt"], shell = True)


您还可以变得更“ pythonic”,并与日志文件配合使用:

 log_file = open("a_log.txt", "a")
 subprocess.call(["ghdl", "-a", "--ieee=synopsys", "-fexplicit", testBenchFile], shell = True, stdout=log_file)


使用stdout参数可以重定向命令的输出,例如>。但是,由于使用模式"a"打开文件,因此您正在模拟>>

关于python - Python:subprocess.call错误“找不到命令”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22177951/

相关文章:

python - 在 Python 中按几个间隔平均列值

python - 使用 Beautiful Soup 从损坏的 <a> 标签中检索内容

Xcode 和 Git 在 MacOSX Mountain Lion 上的安装

linux - Linux 中的 readlink -f 是否有任何方法/替代方法来处理文件夹名称中存在的空格?

python - 从需要标准输入的子进程实时打印标准输出

python - 这本书的章节索引提取程序有改进吗?

python - App Engine : 13 StringPropertys vs. 1 StringListProperty(w.r.t. 索引/存储和查询性能)

ios - 为 iOS 构建 fftw

python - 删除Python中所有子进程的输出而无需访问代码

带引号和变量的 Python Subprocess 命令