Reputation: 19793
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!
Upvotes: 4
Views: 3116
Reputation: 59917
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.
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)
Upvotes: 0