gpt4 book ai didi

python - 在 Windows 机器上帮助 subprocess.call

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

我正在尝试修改 trac允许将 wiki 页面下载到 word 文档的插件。 pagetodoc.py 在此行抛出异常:

# Call the subprocess using convenience method
retval = subprocess.call(command, shell=True, stderr=errptr, stdout=outptr, close_fds = True)

表示 Windows 不支持 close_fds。该过程似乎在 C:\Windows\Temp 中创建了一些临时文件。我尝试删除 close_fds 参数,但随后将子进程写入的文件无限期保持打开状态。稍后写入文件时会抛出异常。这是我第一次使用 Python,我对库不熟悉。这更加困难,因为大多数人可能在 Unix 机器上编写代码。有什么想法可以修改此代码吗?

谢谢!

最佳答案

close_fds is supported on Windows (在该链接后搜索“close_fds”)从 Python 2.6 开始(如果 stdin/stdout/stderr 未重定向) .您可能会考虑升级。

来自链接文档:

Note that on Windows, you cannot set close_fds to true and alsoredirect the standard handles by setting stdin, stdout or stderr.

因此您可以使用close_fds = Truesubprocess.call 并且不设置stdinstdoutstderr(默认)(或将它们设置为 None):

subprocess.call(command, shell=True, close_fds = True)

或者您使用close_fds = Falsesubprocess.call:

subprocess.call(command, shell=True, stderr=errptr, stdout=outptr, close_fds = False)

或者(Python >= 3.2)你让 subprocess.call 自己计算出 close_fds 的值:

subprocess.call(command, shell=True, stderr=errptr, stdout=outptr)

关于python - 在 Windows 机器上帮助 subprocess.call,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/662641/

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