Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/imh-pyth.../lib/python3....
File: subprocess.py
# subprocess - Subprocesses with accessible I/O streams
[0] Fix | Delete
#
[1] Fix | Delete
# For more information about this module, see PEP 324.
[2] Fix | Delete
#
[3] Fix | Delete
# Copyright (c) 2003-2005 by Peter Astrand <astrand@lysator.liu.se>
[4] Fix | Delete
#
[5] Fix | Delete
# Licensed to PSF under a Contributor Agreement.
[6] Fix | Delete
# See http://www.python.org/2.4/license for licensing details.
[7] Fix | Delete
[8] Fix | Delete
r"""Subprocesses with accessible I/O streams
[9] Fix | Delete
[10] Fix | Delete
This module allows you to spawn processes, connect to their
[11] Fix | Delete
input/output/error pipes, and obtain their return codes.
[12] Fix | Delete
[13] Fix | Delete
For a complete description of this module see the Python documentation.
[14] Fix | Delete
[15] Fix | Delete
Main API
[16] Fix | Delete
========
[17] Fix | Delete
run(...): Runs a command, waits for it to complete, then returns a
[18] Fix | Delete
CompletedProcess instance.
[19] Fix | Delete
Popen(...): A class for flexibly executing a command in a new process
[20] Fix | Delete
[21] Fix | Delete
Constants
[22] Fix | Delete
---------
[23] Fix | Delete
DEVNULL: Special value that indicates that os.devnull should be used
[24] Fix | Delete
PIPE: Special value that indicates a pipe should be created
[25] Fix | Delete
STDOUT: Special value that indicates that stderr should go to stdout
[26] Fix | Delete
[27] Fix | Delete
[28] Fix | Delete
Older API
[29] Fix | Delete
=========
[30] Fix | Delete
call(...): Runs a command, waits for it to complete, then returns
[31] Fix | Delete
the return code.
[32] Fix | Delete
check_call(...): Same as call() but raises CalledProcessError()
[33] Fix | Delete
if return code is not 0
[34] Fix | Delete
check_output(...): Same as check_call() but returns the contents of
[35] Fix | Delete
stdout instead of a return code
[36] Fix | Delete
getoutput(...): Runs a command in the shell, waits for it to complete,
[37] Fix | Delete
then returns the output
[38] Fix | Delete
getstatusoutput(...): Runs a command in the shell, waits for it to complete,
[39] Fix | Delete
then returns a (exitcode, output) tuple
[40] Fix | Delete
"""
[41] Fix | Delete
[42] Fix | Delete
import builtins
[43] Fix | Delete
import errno
[44] Fix | Delete
import io
[45] Fix | Delete
import os
[46] Fix | Delete
import time
[47] Fix | Delete
import signal
[48] Fix | Delete
import sys
[49] Fix | Delete
import threading
[50] Fix | Delete
import warnings
[51] Fix | Delete
import contextlib
[52] Fix | Delete
from time import monotonic as _time
[53] Fix | Delete
import types
[54] Fix | Delete
[55] Fix | Delete
try:
[56] Fix | Delete
import pwd
[57] Fix | Delete
except ImportError:
[58] Fix | Delete
pwd = None
[59] Fix | Delete
try:
[60] Fix | Delete
import grp
[61] Fix | Delete
except ImportError:
[62] Fix | Delete
grp = None
[63] Fix | Delete
[64] Fix | Delete
__all__ = ["Popen", "PIPE", "STDOUT", "call", "check_call", "getstatusoutput",
[65] Fix | Delete
"getoutput", "check_output", "run", "CalledProcessError", "DEVNULL",
[66] Fix | Delete
"SubprocessError", "TimeoutExpired", "CompletedProcess"]
[67] Fix | Delete
# NOTE: We intentionally exclude list2cmdline as it is
[68] Fix | Delete
# considered an internal implementation detail. issue10838.
[69] Fix | Delete
[70] Fix | Delete
try:
[71] Fix | Delete
import msvcrt
[72] Fix | Delete
import _winapi
[73] Fix | Delete
_mswindows = True
[74] Fix | Delete
except ModuleNotFoundError:
[75] Fix | Delete
_mswindows = False
[76] Fix | Delete
import _posixsubprocess
[77] Fix | Delete
import select
[78] Fix | Delete
import selectors
[79] Fix | Delete
else:
[80] Fix | Delete
from _winapi import (CREATE_NEW_CONSOLE, CREATE_NEW_PROCESS_GROUP,
[81] Fix | Delete
STD_INPUT_HANDLE, STD_OUTPUT_HANDLE,
[82] Fix | Delete
STD_ERROR_HANDLE, SW_HIDE,
[83] Fix | Delete
STARTF_USESTDHANDLES, STARTF_USESHOWWINDOW,
[84] Fix | Delete
ABOVE_NORMAL_PRIORITY_CLASS, BELOW_NORMAL_PRIORITY_CLASS,
[85] Fix | Delete
HIGH_PRIORITY_CLASS, IDLE_PRIORITY_CLASS,
[86] Fix | Delete
NORMAL_PRIORITY_CLASS, REALTIME_PRIORITY_CLASS,
[87] Fix | Delete
CREATE_NO_WINDOW, DETACHED_PROCESS,
[88] Fix | Delete
CREATE_DEFAULT_ERROR_MODE, CREATE_BREAKAWAY_FROM_JOB)
[89] Fix | Delete
[90] Fix | Delete
__all__.extend(["CREATE_NEW_CONSOLE", "CREATE_NEW_PROCESS_GROUP",
[91] Fix | Delete
"STD_INPUT_HANDLE", "STD_OUTPUT_HANDLE",
[92] Fix | Delete
"STD_ERROR_HANDLE", "SW_HIDE",
[93] Fix | Delete
"STARTF_USESTDHANDLES", "STARTF_USESHOWWINDOW",
[94] Fix | Delete
"STARTUPINFO",
[95] Fix | Delete
"ABOVE_NORMAL_PRIORITY_CLASS", "BELOW_NORMAL_PRIORITY_CLASS",
[96] Fix | Delete
"HIGH_PRIORITY_CLASS", "IDLE_PRIORITY_CLASS",
[97] Fix | Delete
"NORMAL_PRIORITY_CLASS", "REALTIME_PRIORITY_CLASS",
[98] Fix | Delete
"CREATE_NO_WINDOW", "DETACHED_PROCESS",
[99] Fix | Delete
"CREATE_DEFAULT_ERROR_MODE", "CREATE_BREAKAWAY_FROM_JOB"])
[100] Fix | Delete
[101] Fix | Delete
[102] Fix | Delete
# Exception classes used by this module.
[103] Fix | Delete
class SubprocessError(Exception): pass
[104] Fix | Delete
[105] Fix | Delete
[106] Fix | Delete
class CalledProcessError(SubprocessError):
[107] Fix | Delete
"""Raised when run() is called with check=True and the process
[108] Fix | Delete
returns a non-zero exit status.
[109] Fix | Delete
[110] Fix | Delete
Attributes:
[111] Fix | Delete
cmd, returncode, stdout, stderr, output
[112] Fix | Delete
"""
[113] Fix | Delete
def __init__(self, returncode, cmd, output=None, stderr=None):
[114] Fix | Delete
self.returncode = returncode
[115] Fix | Delete
self.cmd = cmd
[116] Fix | Delete
self.output = output
[117] Fix | Delete
self.stderr = stderr
[118] Fix | Delete
[119] Fix | Delete
def __str__(self):
[120] Fix | Delete
if self.returncode and self.returncode < 0:
[121] Fix | Delete
try:
[122] Fix | Delete
return "Command '%s' died with %r." % (
[123] Fix | Delete
self.cmd, signal.Signals(-self.returncode))
[124] Fix | Delete
except ValueError:
[125] Fix | Delete
return "Command '%s' died with unknown signal %d." % (
[126] Fix | Delete
self.cmd, -self.returncode)
[127] Fix | Delete
else:
[128] Fix | Delete
return "Command '%s' returned non-zero exit status %d." % (
[129] Fix | Delete
self.cmd, self.returncode)
[130] Fix | Delete
[131] Fix | Delete
@property
[132] Fix | Delete
def stdout(self):
[133] Fix | Delete
"""Alias for output attribute, to match stderr"""
[134] Fix | Delete
return self.output
[135] Fix | Delete
[136] Fix | Delete
@stdout.setter
[137] Fix | Delete
def stdout(self, value):
[138] Fix | Delete
# There's no obvious reason to set this, but allow it anyway so
[139] Fix | Delete
# .stdout is a transparent alias for .output
[140] Fix | Delete
self.output = value
[141] Fix | Delete
[142] Fix | Delete
[143] Fix | Delete
class TimeoutExpired(SubprocessError):
[144] Fix | Delete
"""This exception is raised when the timeout expires while waiting for a
[145] Fix | Delete
child process.
[146] Fix | Delete
[147] Fix | Delete
Attributes:
[148] Fix | Delete
cmd, output, stdout, stderr, timeout
[149] Fix | Delete
"""
[150] Fix | Delete
def __init__(self, cmd, timeout, output=None, stderr=None):
[151] Fix | Delete
self.cmd = cmd
[152] Fix | Delete
self.timeout = timeout
[153] Fix | Delete
self.output = output
[154] Fix | Delete
self.stderr = stderr
[155] Fix | Delete
[156] Fix | Delete
def __str__(self):
[157] Fix | Delete
return ("Command '%s' timed out after %s seconds" %
[158] Fix | Delete
(self.cmd, self.timeout))
[159] Fix | Delete
[160] Fix | Delete
@property
[161] Fix | Delete
def stdout(self):
[162] Fix | Delete
return self.output
[163] Fix | Delete
[164] Fix | Delete
@stdout.setter
[165] Fix | Delete
def stdout(self, value):
[166] Fix | Delete
# There's no obvious reason to set this, but allow it anyway so
[167] Fix | Delete
# .stdout is a transparent alias for .output
[168] Fix | Delete
self.output = value
[169] Fix | Delete
[170] Fix | Delete
[171] Fix | Delete
if _mswindows:
[172] Fix | Delete
class STARTUPINFO:
[173] Fix | Delete
def __init__(self, *, dwFlags=0, hStdInput=None, hStdOutput=None,
[174] Fix | Delete
hStdError=None, wShowWindow=0, lpAttributeList=None):
[175] Fix | Delete
self.dwFlags = dwFlags
[176] Fix | Delete
self.hStdInput = hStdInput
[177] Fix | Delete
self.hStdOutput = hStdOutput
[178] Fix | Delete
self.hStdError = hStdError
[179] Fix | Delete
self.wShowWindow = wShowWindow
[180] Fix | Delete
self.lpAttributeList = lpAttributeList or {"handle_list": []}
[181] Fix | Delete
[182] Fix | Delete
def copy(self):
[183] Fix | Delete
attr_list = self.lpAttributeList.copy()
[184] Fix | Delete
if 'handle_list' in attr_list:
[185] Fix | Delete
attr_list['handle_list'] = list(attr_list['handle_list'])
[186] Fix | Delete
[187] Fix | Delete
return STARTUPINFO(dwFlags=self.dwFlags,
[188] Fix | Delete
hStdInput=self.hStdInput,
[189] Fix | Delete
hStdOutput=self.hStdOutput,
[190] Fix | Delete
hStdError=self.hStdError,
[191] Fix | Delete
wShowWindow=self.wShowWindow,
[192] Fix | Delete
lpAttributeList=attr_list)
[193] Fix | Delete
[194] Fix | Delete
[195] Fix | Delete
class Handle(int):
[196] Fix | Delete
closed = False
[197] Fix | Delete
[198] Fix | Delete
def Close(self, CloseHandle=_winapi.CloseHandle):
[199] Fix | Delete
if not self.closed:
[200] Fix | Delete
self.closed = True
[201] Fix | Delete
CloseHandle(self)
[202] Fix | Delete
[203] Fix | Delete
def Detach(self):
[204] Fix | Delete
if not self.closed:
[205] Fix | Delete
self.closed = True
[206] Fix | Delete
return int(self)
[207] Fix | Delete
raise ValueError("already closed")
[208] Fix | Delete
[209] Fix | Delete
def __repr__(self):
[210] Fix | Delete
return "%s(%d)" % (self.__class__.__name__, int(self))
[211] Fix | Delete
[212] Fix | Delete
__del__ = Close
[213] Fix | Delete
else:
[214] Fix | Delete
# When select or poll has indicated that the file is writable,
[215] Fix | Delete
# we can write up to _PIPE_BUF bytes without risk of blocking.
[216] Fix | Delete
# POSIX defines PIPE_BUF as >= 512.
[217] Fix | Delete
_PIPE_BUF = getattr(select, 'PIPE_BUF', 512)
[218] Fix | Delete
[219] Fix | Delete
# poll/select have the advantage of not requiring any extra file
[220] Fix | Delete
# descriptor, contrarily to epoll/kqueue (also, they require a single
[221] Fix | Delete
# syscall).
[222] Fix | Delete
if hasattr(selectors, 'PollSelector'):
[223] Fix | Delete
_PopenSelector = selectors.PollSelector
[224] Fix | Delete
else:
[225] Fix | Delete
_PopenSelector = selectors.SelectSelector
[226] Fix | Delete
[227] Fix | Delete
[228] Fix | Delete
if _mswindows:
[229] Fix | Delete
# On Windows we just need to close `Popen._handle` when we no longer need
[230] Fix | Delete
# it, so that the kernel can free it. `Popen._handle` gets closed
[231] Fix | Delete
# implicitly when the `Popen` instance is finalized (see `Handle.__del__`,
[232] Fix | Delete
# which is calling `CloseHandle` as requested in [1]), so there is nothing
[233] Fix | Delete
# for `_cleanup` to do.
[234] Fix | Delete
#
[235] Fix | Delete
# [1] https://docs.microsoft.com/en-us/windows/desktop/ProcThread/
[236] Fix | Delete
# creating-processes
[237] Fix | Delete
_active = None
[238] Fix | Delete
[239] Fix | Delete
def _cleanup():
[240] Fix | Delete
pass
[241] Fix | Delete
else:
[242] Fix | Delete
# This lists holds Popen instances for which the underlying process had not
[243] Fix | Delete
# exited at the time its __del__ method got called: those processes are
[244] Fix | Delete
# wait()ed for synchronously from _cleanup() when a new Popen object is
[245] Fix | Delete
# created, to avoid zombie processes.
[246] Fix | Delete
_active = []
[247] Fix | Delete
[248] Fix | Delete
def _cleanup():
[249] Fix | Delete
if _active is None:
[250] Fix | Delete
return
[251] Fix | Delete
for inst in _active[:]:
[252] Fix | Delete
res = inst._internal_poll(_deadstate=sys.maxsize)
[253] Fix | Delete
if res is not None:
[254] Fix | Delete
try:
[255] Fix | Delete
_active.remove(inst)
[256] Fix | Delete
except ValueError:
[257] Fix | Delete
# This can happen if two threads create a new Popen instance.
[258] Fix | Delete
# It's harmless that it was already removed, so ignore.
[259] Fix | Delete
pass
[260] Fix | Delete
[261] Fix | Delete
PIPE = -1
[262] Fix | Delete
STDOUT = -2
[263] Fix | Delete
DEVNULL = -3
[264] Fix | Delete
[265] Fix | Delete
[266] Fix | Delete
# XXX This function is only used by multiprocessing and the test suite,
[267] Fix | Delete
# but it's here so that it can be imported when Python is compiled without
[268] Fix | Delete
# threads.
[269] Fix | Delete
[270] Fix | Delete
def _optim_args_from_interpreter_flags():
[271] Fix | Delete
"""Return a list of command-line arguments reproducing the current
[272] Fix | Delete
optimization settings in sys.flags."""
[273] Fix | Delete
args = []
[274] Fix | Delete
value = sys.flags.optimize
[275] Fix | Delete
if value > 0:
[276] Fix | Delete
args.append('-' + 'O' * value)
[277] Fix | Delete
return args
[278] Fix | Delete
[279] Fix | Delete
[280] Fix | Delete
def _args_from_interpreter_flags():
[281] Fix | Delete
"""Return a list of command-line arguments reproducing the current
[282] Fix | Delete
settings in sys.flags, sys.warnoptions and sys._xoptions."""
[283] Fix | Delete
flag_opt_map = {
[284] Fix | Delete
'debug': 'd',
[285] Fix | Delete
# 'inspect': 'i',
[286] Fix | Delete
# 'interactive': 'i',
[287] Fix | Delete
'dont_write_bytecode': 'B',
[288] Fix | Delete
'no_site': 'S',
[289] Fix | Delete
'verbose': 'v',
[290] Fix | Delete
'bytes_warning': 'b',
[291] Fix | Delete
'quiet': 'q',
[292] Fix | Delete
# -O is handled in _optim_args_from_interpreter_flags()
[293] Fix | Delete
}
[294] Fix | Delete
args = _optim_args_from_interpreter_flags()
[295] Fix | Delete
for flag, opt in flag_opt_map.items():
[296] Fix | Delete
v = getattr(sys.flags, flag)
[297] Fix | Delete
if v > 0:
[298] Fix | Delete
args.append('-' + opt * v)
[299] Fix | Delete
[300] Fix | Delete
if sys.flags.isolated:
[301] Fix | Delete
args.append('-I')
[302] Fix | Delete
else:
[303] Fix | Delete
if sys.flags.ignore_environment:
[304] Fix | Delete
args.append('-E')
[305] Fix | Delete
if sys.flags.no_user_site:
[306] Fix | Delete
args.append('-s')
[307] Fix | Delete
[308] Fix | Delete
# -W options
[309] Fix | Delete
warnopts = sys.warnoptions[:]
[310] Fix | Delete
bytes_warning = sys.flags.bytes_warning
[311] Fix | Delete
xoptions = getattr(sys, '_xoptions', {})
[312] Fix | Delete
dev_mode = ('dev' in xoptions)
[313] Fix | Delete
[314] Fix | Delete
if bytes_warning > 1:
[315] Fix | Delete
warnopts.remove("error::BytesWarning")
[316] Fix | Delete
elif bytes_warning:
[317] Fix | Delete
warnopts.remove("default::BytesWarning")
[318] Fix | Delete
if dev_mode:
[319] Fix | Delete
warnopts.remove('default')
[320] Fix | Delete
for opt in warnopts:
[321] Fix | Delete
args.append('-W' + opt)
[322] Fix | Delete
[323] Fix | Delete
# -X options
[324] Fix | Delete
if dev_mode:
[325] Fix | Delete
args.extend(('-X', 'dev'))
[326] Fix | Delete
for opt in ('faulthandler', 'tracemalloc', 'importtime',
[327] Fix | Delete
'showrefcount', 'utf8', 'oldparser'):
[328] Fix | Delete
if opt in xoptions:
[329] Fix | Delete
value = xoptions[opt]
[330] Fix | Delete
if value is True:
[331] Fix | Delete
arg = opt
[332] Fix | Delete
else:
[333] Fix | Delete
arg = '%s=%s' % (opt, value)
[334] Fix | Delete
args.extend(('-X', arg))
[335] Fix | Delete
[336] Fix | Delete
return args
[337] Fix | Delete
[338] Fix | Delete
[339] Fix | Delete
def call(*popenargs, timeout=None, **kwargs):
[340] Fix | Delete
"""Run command with arguments. Wait for command to complete or
[341] Fix | Delete
timeout, then return the returncode attribute.
[342] Fix | Delete
[343] Fix | Delete
The arguments are the same as for the Popen constructor. Example:
[344] Fix | Delete
[345] Fix | Delete
retcode = call(["ls", "-l"])
[346] Fix | Delete
"""
[347] Fix | Delete
with Popen(*popenargs, **kwargs) as p:
[348] Fix | Delete
try:
[349] Fix | Delete
return p.wait(timeout=timeout)
[350] Fix | Delete
except: # Including KeyboardInterrupt, wait handled that.
[351] Fix | Delete
p.kill()
[352] Fix | Delete
# We don't call p.wait() again as p.__exit__ does that for us.
[353] Fix | Delete
raise
[354] Fix | Delete
[355] Fix | Delete
[356] Fix | Delete
def check_call(*popenargs, **kwargs):
[357] Fix | Delete
"""Run command with arguments. Wait for command to complete. If
[358] Fix | Delete
the exit code was zero then return, otherwise raise
[359] Fix | Delete
CalledProcessError. The CalledProcessError object will have the
[360] Fix | Delete
return code in the returncode attribute.
[361] Fix | Delete
[362] Fix | Delete
The arguments are the same as for the call function. Example:
[363] Fix | Delete
[364] Fix | Delete
check_call(["ls", "-l"])
[365] Fix | Delete
"""
[366] Fix | Delete
retcode = call(*popenargs, **kwargs)
[367] Fix | Delete
if retcode:
[368] Fix | Delete
cmd = kwargs.get("args")
[369] Fix | Delete
if cmd is None:
[370] Fix | Delete
cmd = popenargs[0]
[371] Fix | Delete
raise CalledProcessError(retcode, cmd)
[372] Fix | Delete
return 0
[373] Fix | Delete
[374] Fix | Delete
[375] Fix | Delete
def check_output(*popenargs, timeout=None, **kwargs):
[376] Fix | Delete
r"""Run command with arguments and return its output.
[377] Fix | Delete
[378] Fix | Delete
If the exit code was non-zero it raises a CalledProcessError. The
[379] Fix | Delete
CalledProcessError object will have the return code in the returncode
[380] Fix | Delete
attribute and output in the output attribute.
[381] Fix | Delete
[382] Fix | Delete
The arguments are the same as for the Popen constructor. Example:
[383] Fix | Delete
[384] Fix | Delete
>>> check_output(["ls", "-l", "/dev/null"])
[385] Fix | Delete
b'crw-rw-rw- 1 root root 1, 3 Oct 18 2007 /dev/null\n'
[386] Fix | Delete
[387] Fix | Delete
The stdout argument is not allowed as it is used internally.
[388] Fix | Delete
To capture standard error in the result, use stderr=STDOUT.
[389] Fix | Delete
[390] Fix | Delete
>>> check_output(["/bin/sh", "-c",
[391] Fix | Delete
... "ls -l non_existent_file ; exit 0"],
[392] Fix | Delete
... stderr=STDOUT)
[393] Fix | Delete
b'ls: non_existent_file: No such file or directory\n'
[394] Fix | Delete
[395] Fix | Delete
There is an additional optional argument, "input", allowing you to
[396] Fix | Delete
pass a string to the subprocess's stdin. If you use this argument
[397] Fix | Delete
you may not also use the Popen constructor's "stdin" argument, as
[398] Fix | Delete
it too will be used internally. Example:
[399] Fix | Delete
[400] Fix | Delete
>>> check_output(["sed", "-e", "s/foo/bar/"],
[401] Fix | Delete
... input=b"when in the course of fooman events\n")
[402] Fix | Delete
b'when in the course of barman events\n'
[403] Fix | Delete
[404] Fix | Delete
By default, all communication is in bytes, and therefore any "input"
[405] Fix | Delete
should be bytes, and the return value will be bytes. If in text mode,
[406] Fix | Delete
any "input" should be a string, and the return value will be a string
[407] Fix | Delete
decoded according to locale encoding, or by "encoding" if set. Text mode
[408] Fix | Delete
is triggered by setting any of text, encoding, errors or universal_newlines.
[409] Fix | Delete
"""
[410] Fix | Delete
if 'stdout' in kwargs:
[411] Fix | Delete
raise ValueError('stdout argument not allowed, it will be overridden.')
[412] Fix | Delete
[413] Fix | Delete
if 'input' in kwargs and kwargs['input'] is None:
[414] Fix | Delete
# Explicitly passing input=None was previously equivalent to passing an
[415] Fix | Delete
# empty string. That is maintained here for backwards compatibility.
[416] Fix | Delete
if kwargs.get('universal_newlines') or kwargs.get('text'):
[417] Fix | Delete
empty = ''
[418] Fix | Delete
else:
[419] Fix | Delete
empty = b''
[420] Fix | Delete
kwargs['input'] = empty
[421] Fix | Delete
[422] Fix | Delete
return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
[423] Fix | Delete
**kwargs).stdout
[424] Fix | Delete
[425] Fix | Delete
[426] Fix | Delete
class CompletedProcess(object):
[427] Fix | Delete
"""A process that has finished running.
[428] Fix | Delete
[429] Fix | Delete
This is returned by run().
[430] Fix | Delete
[431] Fix | Delete
Attributes:
[432] Fix | Delete
args: The list or str args passed to run().
[433] Fix | Delete
returncode: The exit code of the process, negative for signals.
[434] Fix | Delete
stdout: The standard output (None if not captured).
[435] Fix | Delete
stderr: The standard error (None if not captured).
[436] Fix | Delete
"""
[437] Fix | Delete
def __init__(self, args, returncode, stdout=None, stderr=None):
[438] Fix | Delete
self.args = args
[439] Fix | Delete
self.returncode = returncode
[440] Fix | Delete
self.stdout = stdout
[441] Fix | Delete
self.stderr = stderr
[442] Fix | Delete
[443] Fix | Delete
def __repr__(self):
[444] Fix | Delete
args = ['args={!r}'.format(self.args),
[445] Fix | Delete
'returncode={!r}'.format(self.returncode)]
[446] Fix | Delete
if self.stdout is not None:
[447] Fix | Delete
args.append('stdout={!r}'.format(self.stdout))
[448] Fix | Delete
if self.stderr is not None:
[449] Fix | Delete
args.append('stderr={!r}'.format(self.stderr))
[450] Fix | Delete
return "{}({})".format(type(self).__name__, ', '.join(args))
[451] Fix | Delete
[452] Fix | Delete
__class_getitem__ = classmethod(types.GenericAlias)
[453] Fix | Delete
[454] Fix | Delete
[455] Fix | Delete
def check_returncode(self):
[456] Fix | Delete
"""Raise CalledProcessError if the exit code is non-zero."""
[457] Fix | Delete
if self.returncode:
[458] Fix | Delete
raise CalledProcessError(self.returncode, self.args, self.stdout,
[459] Fix | Delete
self.stderr)
[460] Fix | Delete
[461] Fix | Delete
[462] Fix | Delete
def run(*popenargs,
[463] Fix | Delete
input=None, capture_output=False, timeout=None, check=False, **kwargs):
[464] Fix | Delete
"""Run command with arguments and return a CompletedProcess instance.
[465] Fix | Delete
[466] Fix | Delete
The returned instance will have attributes args, returncode, stdout and
[467] Fix | Delete
stderr. By default, stdout and stderr are not captured, and those attributes
[468] Fix | Delete
will be None. Pass stdout=PIPE and/or stderr=PIPE in order to capture them.
[469] Fix | Delete
[470] Fix | Delete
If check is True and the exit code was non-zero, it raises a
[471] Fix | Delete
CalledProcessError. The CalledProcessError object will have the return code
[472] Fix | Delete
in the returncode attribute, and output & stderr attributes if those streams
[473] Fix | Delete
were captured.
[474] Fix | Delete
[475] Fix | Delete
If timeout is given, and the process takes too long, a TimeoutExpired
[476] Fix | Delete
exception will be raised.
[477] Fix | Delete
[478] Fix | Delete
There is an optional argument "input", allowing you to
[479] Fix | Delete
pass bytes or a string to the subprocess's stdin. If you use this argument
[480] Fix | Delete
you may not also use the Popen constructor's "stdin" argument, as
[481] Fix | Delete
it will be used internally.
[482] Fix | Delete
[483] Fix | Delete
By default, all communication is in bytes, and therefore any "input" should
[484] Fix | Delete
be bytes, and the stdout and stderr will be bytes. If in text mode, any
[485] Fix | Delete
"input" should be a string, and stdout and stderr will be strings decoded
[486] Fix | Delete
according to locale encoding, or by "encoding" if set. Text mode is
[487] Fix | Delete
triggered by setting any of text, encoding, errors or universal_newlines.
[488] Fix | Delete
[489] Fix | Delete
The other arguments are the same as for the Popen constructor.
[490] Fix | Delete
"""
[491] Fix | Delete
if input is not None:
[492] Fix | Delete
if kwargs.get('stdin') is not None:
[493] Fix | Delete
raise ValueError('stdin and input arguments may not both be used.')
[494] Fix | Delete
kwargs['stdin'] = PIPE
[495] Fix | Delete
[496] Fix | Delete
if capture_output:
[497] Fix | Delete
if kwargs.get('stdout') is not None or kwargs.get('stderr') is not None:
[498] Fix | Delete
raise ValueError('stdout and stderr arguments may not be used '
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function