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

标签 python trac python-2.4

我正在尝试修改 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 also redirect 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/

相关文章:

svn - 如何调整 WordPress URL 处理以忽略某些目录?

python - 使用 python 2.4 计算 CSV 文件中的列数

python - telnetlib python 示例

python - 如何仅打印输出的最大值

svn - 我怎样才能最好地利用 Trac?

python - 在 Python 上使用多进程与 API 请求和多个 for 循环

sqlite - 如何在 Trac 的特定日期创建包含关闭工单的报告

python - 在 python 中高效写入 Compact Flash

python - 如何在文本文件中搜索字符串?

python - 将大型 csv 转换为稀疏矩阵以在 sklearn 中使用