Help with subprocess.call on a Windows computer

I am trying to modify the trac plugin that allows loading wiki pages into text 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)

A statement that is close_fdsnot supported on Windows. It seems that the process is creating some temporary files in C: \ Windows \ Temp. I tried to remove the parameter close_fds, but then it writes the subprocesses to stay open indefinitely. Then an exception is thrown when files are written later. This is my first experience with Python, and I am not familiar with libraries. This is even more complicated since most people are probably encoded on Unix machines. Any ideas how I can redo this code?

Thanks!

+3
source share
1 answer

close_fds supported on Windows (look for "close_fds" after this link) starting with Python 2.6 (ifstdin/stdout/ arestderrnot redirected). You may consider updating.

UPDATE 2017-11-16 after the vote (why?) : From a related document:

Note that on Windows you cannot set close_fds to true, nor can you redirect standard descriptors by setting stdin, stdout or stderr.

So you can subprocess.callto close_fds = Truenot install stdin, stdoutor stderr(default) (or set them on None):

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

or subprocess.callwith close_fds = False:

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)

0

Source: https://habr.com/ru/post/1705032/


All Articles