gpt4 book ai didi

Python 2.5 subprocess.Popen 问题

转载 作者:行者123 更新时间:2023-11-28 21:29:30 24 4
gpt4 key购买 nike

我正在尝试运行以下 Python 小脚本:

#!/usr/local/bin/python2.5
import sys, subprocess
child = subprocess.Popen("muscle -stable -FASTA",
stdin=sys.stdin,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=(sys.platform!="win32"))
print child.stderr.read()
print child.stdout.read()

如果 stdin 不超过大约 3750 个字符,则效果很好。超过此限制,子进程将不再生成任何 stdoutstderr。如果我分别将它们切换为 sys.stdout 和 sys.stderr ,一切都会按预期再次工作。从命令行调用时,muscle 可执行文件会写入 stdoutstderr

有什么建议可能是什么原因以及如何解决这个问题吗? - 最好不要更新 Python,因为安装是在我访问权限有限的服务器上。

最佳答案

使用子项。 communicate(someinput)获得完整的输出;另请参阅文档中的“警告”框。如果您确实需要在写入 stdout 时以交互方式读取 stdin,那么(至少在 Windows 上)您可能无法使用 Python + 管道。

关于Python 2.5 subprocess.Popen 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5426487/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com