2727
2828class Popen(args, bufsize=0, executable=None,
2929 stdin=None, stdout=None, stderr=None,
30- preexec_fn=None, close_fds=False , shell=False,
30+ preexec_fn=None, close_fds=_PLATFORM_DEFAULT , shell=False,
3131 cwd=None, env=None, universal_newlines=False,
3232 startupinfo=None, creationflags=0,
3333 restore_signals=True, start_new_session=False):
@@ -39,12 +39,12 @@ class Popen(args, bufsize=0, executable=None,
3939program to execute is normally the first item in the args sequence or
4040string, but can be explicitly set by using the executable argument.
4141
42- On UNIX , with shell=False (default): In this case, the Popen class
42+ On POSIX , with shell=False (default): In this case, the Popen class
4343uses os.execvp() to execute the child program. args should normally
4444be a sequence. A string will be treated as a sequence with the string
4545as the only item (the program to execute).
4646
47- On UNIX , with shell=True: If args is a string, it specifies the
47+ On POSIX , with shell=True: If args is a string, it specifies the
4848command string to execute through the shell. If args is a sequence,
4949the first item specifies the command string, and any additional items
5050will be treated as additional shell arguments.
@@ -73,35 +73,37 @@ class Popen(args, bufsize=0, executable=None,
7373stderr data from the applications should be captured into the same
7474file handle as for stdout.
7575
76- On UNIX , if preexec_fn is set to a callable object, this object will be
76+ On POSIX , if preexec_fn is set to a callable object, this object will be
7777called in the child process just before the child is executed. The use
7878of preexec_fn is not thread safe, using it in the presence of threads
7979could lead to a deadlock in the child process before the new executable
8080is executed.
8181
8282If close_fds is true, all file descriptors except 0, 1 and 2 will be
83- closed before the child process is executed.
83+ closed before the child process is executed. The default for close_fds
84+ varies by platform: False on Windows and True on all other platforms
85+ such as POSIX.
8486
8587if shell is true, the specified command will be executed through the
8688shell.
8789
8890If cwd is not None, the current directory will be changed to cwd
8991before the child is executed.
9092
91- On UNIX , if restore_signals is True all signals that Python sets to
93+ On POSIX , if restore_signals is True all signals that Python sets to
9294SIG_IGN are restored to SIG_DFL in the child process before the exec.
9395Currently this includes the SIGPIPE, SIGXFZ and SIGXFSZ signals. This
9496parameter does nothing on Windows.
9597
96- On UNIX , if start_new_session is True, the setsid() system call will be made
98+ On POSIX , if start_new_session is True, the setsid() system call will be made
9799in the child process prior to executing the command.
98100
99101If env is not None, it defines the environment variables for the new
100102process.
101103
102104If universal_newlines is true, the file objects stdout and stderr are
103105opened as a text files, but lines may be terminated by any of '\n',
104- the Unix end-of-line convention, '\r', the Macintosh convention or
106+ the Unix end-of-line convention, '\r', the old Macintosh convention or
105107'\r\n', the Windows convention. All of these external representations
106108are seen as '\n' by the Python program. Note: This feature is only
107109available if Python is built with universal newline support (the
@@ -242,7 +244,7 @@ class Popen(args, bufsize=0, executable=None,
242244returncode
243245 The child return code. A None value indicates that the process
244246 hasn't terminated yet. A negative value -N indicates that the
245- child was terminated by signal N (UNIX only).
247+ child was terminated by signal N (POSIX only).
246248
247249
248250Replacing older functions with the subprocess module
@@ -562,7 +564,7 @@ def list2cmdline(seq):
562564
563565# Various tools for executing commands and looking at their output and status.
564566#
565- # NB This only works (and is only relevant) for UNIX .
567+ # NB This only works (and is only relevant) for POSIX .
566568
567569def getstatusoutput (cmd ):
568570 """Return (status, output) of executing cmd in a shell.
@@ -602,10 +604,16 @@ def getoutput(cmd):
602604 return getstatusoutput (cmd )[1 ]
603605
604606
607+ if mswindows :
608+ _PLATFORM_DEFAULT = False
609+ else :
610+ _PLATFORM_DEFAULT = True
611+
612+
605613class Popen (object ):
606614 def __init__ (self , args , bufsize = 0 , executable = None ,
607615 stdin = None , stdout = None , stderr = None ,
608- preexec_fn = None , close_fds = None , shell = False ,
616+ preexec_fn = None , close_fds = _PLATFORM_DEFAULT , shell = False ,
609617 cwd = None , env = None , universal_newlines = False ,
610618 startupinfo = None , creationflags = 0 ,
611619 restore_signals = True , start_new_session = False ,
@@ -619,15 +627,6 @@ def __init__(self, args, bufsize=0, executable=None,
619627 if not isinstance (bufsize , int ):
620628 raise TypeError ("bufsize must be an integer" )
621629
622- if close_fds is None :
623- # Notification for http://bugs.python.org/issue7213 & issue2320
624- warnings .warn (
625- 'The close_fds parameter was not specified. Its default'
626- ' behavior will change in a future Python version. '
627- ' Most users should set it to True. Please'
628- ' update your code explicitly set close_fds.' ,
629- DeprecationWarning )
630-
631630 if mswindows :
632631 if preexec_fn is not None :
633632 raise ValueError ("preexec_fn is not supported on Windows "
0 commit comments