~pythonregexp2.7/python/issue2636-11

« back to all changes in this revision

Viewing changes to Doc/library/subprocess.rst

  • Committer: Jeffrey C. "The TimeHorse" Jacobs
  • Date: 2008-09-21 13:47:31 UTC
  • mfrom: (39021.1.404 Regexp-2.7)
  • mto: This revision was merged to the branch mainline in revision 39030.
  • Revision ID: darklord@timehorse.com-20080921134731-rudomuzeh1b2tz1y
Merged in changes from the latest python source snapshot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
Information about how the :mod:`subprocess` module can be used to replace these
24
24
modules and functions can be found in the following sections.
25
25
 
 
26
.. seealso::
 
27
 
 
28
   :pep:`324` -- PEP proposing the subprocess module
 
29
 
26
30
 
27
31
Using the subprocess Module
28
32
---------------------------
34
38
 
35
39
   Arguments are:
36
40
 
37
 
   *args* should be a string, or a sequence of program arguments.  The program to
38
 
   execute is normally the first item in the args sequence or string, but can be
39
 
   explicitly set by using the executable argument.
 
41
   *args* should be a string, or a sequence of program arguments.  The program
 
42
   to execute is normally the first item in the args sequence or the string if a
 
43
   string is given, but can be explicitly set by using the *executable*
 
44
   argument.
40
45
 
41
46
   On Unix, with *shell=False* (default): In this case, the Popen class uses
42
47
   :meth:`os.execvp` to execute the child program. *args* should normally be a
99
104
 
100
105
   If *universal_newlines* is :const:`True`, the file objects stdout and stderr are
101
106
   opened as text files, but lines may be terminated by any of ``'\n'``, the Unix
102
 
   end-of-line convention, ``'\r'``, the Macintosh convention or ``'\r\n'``, the
 
107
   end-of-line convention, ``'\r'``, the old Macintosh convention or ``'\r\n'``, the
103
108
   Windows convention. All of these external representations are seen as ``'\n'``
104
109
   by the Python program.
105
110
 
188
193
   Wait for child process to terminate.  Set and return :attr:`returncode`
189
194
   attribute.
190
195
 
 
196
   .. warning::
 
197
 
 
198
      This will deadlock if the child process generates enough output to a
 
199
      stdout or stderr pipe such that it blocks waiting for the OS pipe buffer
 
200
      to accept more data.  Use :meth:`communicate` to avoid that.
 
201
 
191
202
 
192
203
.. method:: Popen.communicate(input=None)
193
204
 
240
251
 
241
252
The following attributes are also available:
242
253
 
 
254
.. warning::
 
255
 
 
256
   Use :meth:`communicate` rather than :meth:`.stdin.write`,
 
257
   :meth:`.stdout.read` or :meth:`.stderr.read` to avoid deadlocks due
 
258
   to any of the other OS pipe buffers filling up and blocking the child
 
259
   process.
 
260
 
 
261
 
243
262
.. attribute:: Popen.stdin
244
263
 
245
264
   If the *stdin* argument is ``PIPE``, this attribute is a file object that
273
292
   ``N`` (Unix only).
274
293
 
275
294
 
 
295
.. _subprocess-replacements:
 
296
 
276
297
Replacing Older Functions with the subprocess Module
277
298
----------------------------------------------------
278
299
 
370
391
 
371
392
::
372
393
 
373
 
   pipe = os.popen(cmd, mode='r', bufsize)
 
394
   pipe = os.popen(cmd, 'r', bufsize)
374
395
   ==>
375
396
   pipe = Popen(cmd, shell=True, bufsize=bufsize, stdout=PIPE).stdout
376
397
 
377
398
::
378
399
 
379
 
   pipe = os.popen(cmd, mode='w', bufsize)
 
400
   pipe = os.popen(cmd, 'w', bufsize)
380
401
   ==>
381
402
   pipe = Popen(cmd, shell=True, bufsize=bufsize, stdin=PIPE).stdin
382
403