我对python子流程模块有一个问题
import os, subprocess
BLEU_SCRIPT_PATH = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'multi-bleu.perl')
command = BLEU_SCRIPT_PATH + ' %s < %s'
ref = "ref.en-fr.test.txt"
hyp = "hyp100.en-fr.test.txt"
p = subprocess.Popen(command % (ref, hyp), stdout=subprocess.PIPE, shell=True)
result = p.communicate()[0].decode("utf-8")
# ...
# ...
multi-bleu.perl文件进行计算并返回实数或错误(如果有);但这不是我关心的。
最后一行代码使用我的默认文本编辑器自动打开multi-bleu.perl文件,停止程序执行,直到我手动关闭该文件。
如何禁用此行为
我不认为
subprocess.Popen
解释文件中的任何shebang。您需要在要执行的命令中指定可执行文件。此外,Popen需要一个列表作为第一个参数,因此您需要将字符串格式“提升”到命令列表中您可能还想看看^{} ,这将使代码更容易一些
谢谢你的帮助,非常有帮助。我在linux平台上编写代码(显然有一个默认的perl解释器),当我回到windows时,我并没有注意到这种方式。一旦安装了perl解释器并将其添加到环境中(您建议的内容):
相关问题 更多 >
编程相关推荐