27
27
28
28
class Popen(args, bufsize=0, executable=None,
29
29
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,
31
31
cwd=None, env=None, universal_newlines=False,
32
32
startupinfo=None, creationflags=0,
33
33
restore_signals=True, start_new_session=False):
@@ -39,12 +39,12 @@ class Popen(args, bufsize=0, executable=None,
39
39
program to execute is normally the first item in the args sequence or
40
40
string, but can be explicitly set by using the executable argument.
41
41
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
43
43
uses os.execvp() to execute the child program. args should normally
44
44
be a sequence. A string will be treated as a sequence with the string
45
45
as the only item (the program to execute).
46
46
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
48
48
command string to execute through the shell. If args is a sequence,
49
49
the first item specifies the command string, and any additional items
50
50
will be treated as additional shell arguments.
@@ -73,35 +73,37 @@ class Popen(args, bufsize=0, executable=None,
73
73
stderr data from the applications should be captured into the same
74
74
file handle as for stdout.
75
75
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
77
77
called in the child process just before the child is executed. The use
78
78
of preexec_fn is not thread safe, using it in the presence of threads
79
79
could lead to a deadlock in the child process before the new executable
80
80
is executed.
81
81
82
82
If 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.
84
86
85
87
if shell is true, the specified command will be executed through the
86
88
shell.
87
89
88
90
If cwd is not None, the current directory will be changed to cwd
89
91
before the child is executed.
90
92
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
92
94
SIG_IGN are restored to SIG_DFL in the child process before the exec.
93
95
Currently this includes the SIGPIPE, SIGXFZ and SIGXFSZ signals. This
94
96
parameter does nothing on Windows.
95
97
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
97
99
in the child process prior to executing the command.
98
100
99
101
If env is not None, it defines the environment variables for the new
100
102
process.
101
103
102
104
If universal_newlines is true, the file objects stdout and stderr are
103
105
opened 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
105
107
'\r\n', the Windows convention. All of these external representations
106
108
are seen as '\n' by the Python program. Note: This feature is only
107
109
available if Python is built with universal newline support (the
@@ -242,7 +244,7 @@ class Popen(args, bufsize=0, executable=None,
242
244
returncode
243
245
The child return code. A None value indicates that the process
244
246
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).
246
248
247
249
248
250
Replacing older functions with the subprocess module
@@ -562,7 +564,7 @@ def list2cmdline(seq):
562
564
563
565
# Various tools for executing commands and looking at their output and status.
564
566
#
565
- # NB This only works (and is only relevant) for UNIX .
567
+ # NB This only works (and is only relevant) for POSIX .
566
568
567
569
def getstatusoutput (cmd ):
568
570
"""Return (status, output) of executing cmd in a shell.
@@ -602,10 +604,16 @@ def getoutput(cmd):
602
604
return getstatusoutput (cmd )[1 ]
603
605
604
606
607
+ if mswindows :
608
+ _PLATFORM_DEFAULT = False
609
+ else :
610
+ _PLATFORM_DEFAULT = True
611
+
612
+
605
613
class Popen (object ):
606
614
def __init__ (self , args , bufsize = 0 , executable = None ,
607
615
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 ,
609
617
cwd = None , env = None , universal_newlines = False ,
610
618
startupinfo = None , creationflags = 0 ,
611
619
restore_signals = True , start_new_session = False ,
@@ -619,15 +627,6 @@ def __init__(self, args, bufsize=0, executable=None,
619
627
if not isinstance (bufsize , int ):
620
628
raise TypeError ("bufsize must be an integer" )
621
629
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
-
631
630
if mswindows :
632
631
if preexec_fn is not None :
633
632
raise ValueError ("preexec_fn is not supported on Windows "
0 commit comments