[Python-checkins] r55604 - in python/trunk: Doc/lib/libsubprocess.tex Lib/subprocess.py Lib/test/test_subprocess.py
peter.astrand
python-checkins at python.org
Sun May 27 00:18:26 CEST 2007
Author: peter.astrand
Date: Sun May 27 00:18:20 2007
New Revision: 55604
Modified:
python/trunk/Doc/lib/libsubprocess.tex
python/trunk/Lib/subprocess.py
python/trunk/Lib/test/test_subprocess.py
Log:
Applied patch 1669481, slightly modified: Support close_fds on Win32
Modified: python/trunk/Doc/lib/libsubprocess.tex
==============================================================================
--- python/trunk/Doc/lib/libsubprocess.tex (original)
+++ python/trunk/Doc/lib/libsubprocess.tex Sun May 27 00:18:20 2007
@@ -89,7 +89,10 @@
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
-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
executed through the shell.
Modified: python/trunk/Lib/subprocess.py
==============================================================================
--- python/trunk/Lib/subprocess.py (original)
+++ python/trunk/Lib/subprocess.py Sun May 27 00:18:20 2007
@@ -545,9 +545,10 @@
if preexec_fn is not None:
raise ValueError("preexec_fn is not supported on Windows "
"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 "
- "platforms")
+ "platforms if you redirect stdin/stdout/stderr")
else:
# POSIX
if startupinfo is not None:
@@ -804,9 +805,7 @@
hp, ht, pid, tid = CreateProcess(executable, args,
# no special security
None, None,
- # must inherit handles to pass std
- # handles
- 1,
+ int(not close_fds),
creationflags,
env,
cwd,
Modified: python/trunk/Lib/test/test_subprocess.py
==============================================================================
--- python/trunk/Lib/test/test_subprocess.py (original)
+++ python/trunk/Lib/test/test_subprocess.py Sun May 27 00:18:20 2007
@@ -617,8 +617,16 @@
self.assertRaises(ValueError, subprocess.call,
[sys.executable,
"-c", "import sys; sys.exit(47)"],
+ stdout=subprocess.PIPE,
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):
# Run command through the shell (sequence)
newenv = os.environ.copy()
More information about the Python-checkins
mailing list