我正在使用只能在 bash 中运行的科学软件(称为 vasp),并使用 Python 创建一个脚本,该脚本将为我运行多次。当我使用 subprocess.check_call 正常调用该函数时,它工作正常,但是当我添加 '| tee tee_output' 它不起作用。
subprocess.check_call('vasp') #this works
subprocess.check_call('vasp | tee tee_output') #this doesn't
我对 Python 和编程一窍不通。
最佳答案
试试这个。它通过 shell 执行命令(作为字符串传递),而不是直接执行命令。 (这相当于使用 -c
标志调用 shell 本身,即 Popen(['/bin/sh', '-c', args[0], args[1] , ...])
):
subprocess.check_call('vasp | tee tee_output', shell=True)
但请注意 docs 中的警告关于这个方法。
关于python - 如何使用 | 调用多个 bash 函数在 python ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9609375/