Commit 81a191b3 authored by Peter Astrand's avatar Peter Astrand

Applied patch 1669481, slightly modified: Support close_fds on Win32

parent 5f9b6c9a
...@@ -89,7 +89,10 @@ called in the child process just before the child is executed. ...@@ -89,7 +89,10 @@ called in the child process just before the child is executed.
If \var{close_fds} is true, all file descriptors except \constant{0}, If \var{close_fds} is true, all file descriptors except \constant{0},
\constant{1} and \constant{2} will be closed before the child process is \constant{1} and \constant{2} will be closed before the child process is
executed. (\UNIX{} only) executed. (\UNIX{} only). Or, on Windows, if \var{close_fds} is true
then no handles will be inherited by the child process. Note that on
Windows, you cannot set \var{close_fds} to true and also redirect the
standard handles by setting \var{stdin}, \var{stdout} or \var{stderr}.
If \var{shell} is \constant{True}, the specified command will be If \var{shell} is \constant{True}, the specified command will be
executed through the shell. executed through the shell.
......
...@@ -545,9 +545,10 @@ class Popen(object): ...@@ -545,9 +545,10 @@ class Popen(object):
if preexec_fn is not None: if preexec_fn is not None:
raise ValueError("preexec_fn is not supported on Windows " raise ValueError("preexec_fn is not supported on Windows "
"platforms") "platforms")
if close_fds: if close_fds and (stdin is not None or stdout is not None or
stderr is not None):
raise ValueError("close_fds is not supported on Windows " raise ValueError("close_fds is not supported on Windows "
"platforms") "platforms if you redirect stdin/stdout/stderr")
else: else:
# POSIX # POSIX
if startupinfo is not None: if startupinfo is not None:
...@@ -804,9 +805,7 @@ class Popen(object): ...@@ -804,9 +805,7 @@ class Popen(object):
hp, ht, pid, tid = CreateProcess(executable, args, hp, ht, pid, tid = CreateProcess(executable, args,
# no special security # no special security
None, None, None, None,
# must inherit handles to pass std int(not close_fds),
# handles
1,
creationflags, creationflags,
env, env,
cwd, cwd,
......
...@@ -617,8 +617,16 @@ class ProcessTestCase(unittest.TestCase): ...@@ -617,8 +617,16 @@ class ProcessTestCase(unittest.TestCase):
self.assertRaises(ValueError, subprocess.call, self.assertRaises(ValueError, subprocess.call,
[sys.executable, [sys.executable,
"-c", "import sys; sys.exit(47)"], "-c", "import sys; sys.exit(47)"],
stdout=subprocess.PIPE,
close_fds=True) close_fds=True)
def test_close_fds(self):
# close file descriptors
rc = subprocess.call([sys.executable, "-c",
"import sys; sys.exit(47)"],
close_fds=True)
self.assertEqual(rc, 47)
def test_shell_sequence(self): def test_shell_sequence(self):
# Run command through the shell (sequence) # Run command through the shell (sequence)
newenv = os.environ.copy() newenv = os.environ.copy()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment