有关 Windows 计算机上的 subprocess.call 的帮助
我正在尝试修改 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 机器上编码。 我有什么想法可以重新编写这段代码吗?
谢谢!
I am trying to modify a trac plugin that allows downloading of wiki pages to word documents. pagetodoc.py throws an exception on this line:
# Call the subprocess using convenience method
retval = subprocess.call(command, shell=True, stderr=errptr, stdout=outptr, close_fds = True)
Saying that close_fds
is not supported on Windows. The process seems to create some temporary files in C:\Windows\Temp. I tried removing the close_fds
parameter, but then files the subprocess writes to stay open indefinitely. An exception is then thrown when the files are written to later. This is my first time working with Python, and I am not familiar with the libraries. It is even more difficult since most people probably code on Unix machines. Any ideas how I can rework this code?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
close_fds
是 Windows 支持(在该链接后搜索“close_fds”)从 Python 2.6 开始(如果stdin
/stdout
/stderr
不会被重定向)。 您可以考虑升级。从链接的文档:
因此,您可以将
subprocess.call
与close_fds = True
结合使用,而不设置stdin
、stdout
或stderr
(默认)(或将它们设置为None
):或
subprocess.call
与close_fds = False
:或 (Python >= 3.2) 你让
subprocess.call
计算单独输出close_fds
的值:close_fds
is supported on Windows (search for "close_fds" after that link) starting with Python 2.6 (ifstdin
/stdout
/stderr
are not redirected). You might consider upgrading.From the linked doc:
So you can either
subprocess.call
withclose_fds = True
and not settingstdin
,stdout
orstderr
(the default) (or setting them toNone
):or you
subprocess.call
withclose_fds = False
:or (Python >= 3.2) you let
subprocess.call
figure out the value ofclose_fds
by itself: