3

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

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

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

谢谢!

4

1 回答 1

0

close_fds is supported on Windows (search for "close_fds" after that link) starting with Python 2.6 (if stdin/stdout/stderr are not redirected). You might consider upgrading.

UPDATE 2017-11-16 after a down vote (why?): From the linked doc:

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

So you can either subprocess.call with close_fds = True and not setting stdin, stdout or stderr (the default) (or setting them to None):

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

or you subprocess.call with close_fds = False:

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

or (Python >= 3.2) you let subprocess.call figure out the value of close_fds by itself:

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

于 2009-03-19T16:59:33.107 回答