Lines Matching +full:- +full:- +full:shell
2 :mod:`subprocess` --- Subprocess management
24 functions can be found in the subprocess-replacements_ section.
33 :pep:`324` -- PEP proposing the subprocess module
38 ----------------------------------
45 .. function:: call(args, *, stdin=None, stdout=None, stderr=None, shell=False)
51 in :ref:`frequently-used-arguments` (hence the slightly odd notation in
53 that of the :class:`Popen` constructor - this functions passes all
58 >>> subprocess.call(["ls", "-l"])
61 >>> subprocess.call("exit 1", shell=True)
66 Using ``shell=True`` can be a security hazard. See the warning
67 under :ref:`frequently-used-arguments` for details.
77 .. function:: check_call(args, *, stdin=None, stdout=None, stderr=None, shell=False)
85 in :ref:`frequently-used-arguments` (hence the slightly odd notation in
87 that of the :class:`Popen` constructor - this functions passes all
92 >>> subprocess.check_call(["ls", "-l"])
95 >>> subprocess.check_call("exit 1", shell=True)
98 subprocess.CalledProcessError: Command 'exit 1' returned non-zero exit status 1
104 Using ``shell=True`` can be a security hazard. See the warning
105 under :ref:`frequently-used-arguments` for details.
115 .. function:: check_output(args, *, stdin=None, stderr=None, shell=False, universal_newlines=False)
119 If the return code was non-zero it raises a :exc:`CalledProcessError`. The
125 in :ref:`frequently-used-arguments` (hence the slightly odd notation in
136 >>> subprocess.check_output("exit 1", shell=True)
139 subprocess.CalledProcessError: Command 'exit 1' returned non-zero exit status 1
147 ... shell=True)
154 Using ``shell=True`` can be a security hazard. See the warning
155 under :ref:`frequently-used-arguments` for details.
181 :func:`check_output` returns a non-zero exit status.
198 .. _frequently-used-arguments:
212 a single string, either *shell* must be :const:`True` (see below) or else
233 If *shell* is ``True``, the specified command will be executed through
234 the shell. This can be useful if you are using Python primarily for the
236 convenient access to other shell features such as shell pipes, filename
239 implementations of many shell-like features (in particular, :mod:`glob`,
245 Executing shell commands that incorporate unsanitized input from an
246 untrusted source makes a program vulnerable to `shell injection
249 For this reason, the use of ``shell=True`` is **strongly discouraged**
255 non_existent; rm -rf / #
256 >>> call("cat " + filename, shell=True) # Uh-oh. This will end badly...
258 ``shell=False`` disables all shell based features, but does not suffer
260 documentation for helpful hints in getting ``shell=False`` to work.
262 When using ``shell=True``, :func:`pipes.quote` can be used to properly
263 escape whitespace and shell metacharacters in strings that are going to
264 be used to construct shell commands.
280 stderr=None, preexec_fn=None, close_fds=False, shell=False, \
285 :meth:`os.execvp`-like behavior to execute the child program. On Windows,
292 platform-dependent and described below. See the *shell* and *executable*
307 /bin/vikings -input eggs.txt -output "spam spam.txt" -cmd "echo '$MONEY'"
310 ['/bin/vikings', '-input', 'eggs.txt', '-output', 'spam spam.txt', '-cmd', "echo '$MONEY'"]
313 Note in particular that options (such as *-input*) and arguments (such
314 as *eggs.txt*) that are separated by whitespace in the shell go in separate
316 used in the shell (such as filenames containing spaces or the *echo* command
320 manner described in :ref:`converting-argument-sequence`. This is because
323 The *shell* argument (which defaults to ``False``) specifies whether to use
324 the shell as the program to execute. If *shell* is ``True``, it is
327 On Unix with ``shell=True``, the shell defaults to :file:`/bin/sh`. If
329 to execute through the shell. This means that the string must be
330 formatted exactly as it would be when typed at the shell prompt. This
333 any additional items will be treated as additional arguments to the shell
336 Popen(['/bin/sh', '-c', args[0], args[1], ...])
338 On Windows with ``shell=True``, the :envvar:`COMSPEC` environment variable
339 specifies the default shell. The only time you need to specify
340 ``shell=True`` on Windows is when the command you wish to execute is built
341 into the shell (e.g. :command:`dir` or :command:`copy`). You do not need
342 ``shell=True`` to run a batch file or console-based executable.
346 Passing ``shell=True`` can be a security hazard if combined with
347 untrusted input. See the warning under :ref:`frequently-used-arguments`
351 built-in open() function: :const:`0` means unbuffered, :const:`1` means line
359 enable buffering by setting *bufsize* to either -1 or a large enough
363 is very seldom needed. When ``shell=False``, *executable* replaces the
369 :program:`ps`. If ``shell=True``, on Unix the *executable* argument
370 specifies a replacement shell for the default :file:`/bin/sh`.
404 `side-by-side assembly`_ the specified *env* **must** include a valid
407 .. _side-by-side assembly: https://en.wikipedia.org/wiki/Side-by-Side_Assembly
411 terminated by any of ``'\n'``, the Unix end-of-line convention, ``'\r'``,
432 execute, will be re-raised in the parent. Additionally, the exception object
437 when trying to execute a non-existent file. Applications should prepare for
444 :exc:`CalledProcessError` if the called process returns a non-zero return
452 system shell implicitly. This means that all characters, including shell
454 shell is invoked explicitly, then it is the application's responsibility to
459 -------------
486 until end-of-file is reached. Wait for process to terminate. The optional
566 Note that if you set the *shell* argument to ``True``, this is the process ID
567 of the spawned shell.
576 A negative value ``-N`` indicates that the child was terminated by signal
581 ---------------------
589 `STARTUPINFO <https://msdn.microsoft.com/en-us/library/ms686331(v=vs.85).aspx>`__
625 `ShowWindow <https://msdn.microsoft.com/en-us/library/ms633548(v=vs.85).aspx>`__
630 :class:`Popen` is called with ``shell=True``.
673 This flag is always set when :class:`Popen` is created with ``shell=True``.
684 .. _subprocess-replacements:
687 -----------------------------------------------------------
698 :exc:`CalledProcessError` if the requested operation produces a non-zero
706 Replacing /bin/sh shell backquote
709 .. code-block:: bash
717 Replacing shell pipeline
720 .. code-block:: bash
734 Alternatively, for trusted input, the shell's own pipeline support may still
737 .. code-block:: bash
743 output=check_output("dmesg | grep hda", shell=True)
753 status = subprocess.call("mycmd" + " myarg", shell=True)
757 * Calling the program through the shell is usually not required.
762 retcode = call("mycmd" + " myarg", shell=True)
764 print >>sys.stderr, "Child was terminated by signal", -retcode
806 pipe = Popen("cmd", shell=True, bufsize=bufsize, stdout=PIPE).stdout
812 pipe = Popen("cmd", shell=True, bufsize=bufsize, stdin=PIPE).stdin
818 p = Popen("cmd", shell=True, bufsize=bufsize,
828 p = Popen("cmd", shell=True, bufsize=bufsize,
839 p = Popen("cmd", shell=True, bufsize=bufsize,
845 directly to the program without shell intervention. This usage can be
848 (child_stdin, child_stdout) = os.popen2(["/bin/ls", "-l"], mode,
851 p = Popen(["/bin/ls", "-l"], bufsize=bufsize, stdin=PIPE, stdout=PIPE)
862 process = Popen("cmd", shell=True, stdin=PIPE)
876 p = Popen("somestring", shell=True, bufsize=bufsize,
882 shell intervention. This usage can be replaced as follows::
905 -----
907 .. _converting-argument-sequence: