Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../usr/lib64/python3....
File: subprocess.py
# Add remaining backslashes, if any.
[500] Fix | Delete
if bs_buf:
[501] Fix | Delete
result.extend(bs_buf)
[502] Fix | Delete
[503] Fix | Delete
if needquote:
[504] Fix | Delete
result.extend(bs_buf)
[505] Fix | Delete
result.append('"')
[506] Fix | Delete
[507] Fix | Delete
return ''.join(result)
[508] Fix | Delete
[509] Fix | Delete
[510] Fix | Delete
# Various tools for executing commands and looking at their output and status.
[511] Fix | Delete
#
[512] Fix | Delete
[513] Fix | Delete
def getstatusoutput(cmd):
[514] Fix | Delete
"""Return (exitcode, output) of executing cmd in a shell.
[515] Fix | Delete
[516] Fix | Delete
Execute the string 'cmd' in a shell with 'check_output' and
[517] Fix | Delete
return a 2-tuple (status, output). The locale encoding is used
[518] Fix | Delete
to decode the output and process newlines.
[519] Fix | Delete
[520] Fix | Delete
A trailing newline is stripped from the output.
[521] Fix | Delete
The exit status for the command can be interpreted
[522] Fix | Delete
according to the rules for the function 'wait'. Example:
[523] Fix | Delete
[524] Fix | Delete
>>> import subprocess
[525] Fix | Delete
>>> subprocess.getstatusoutput('ls /bin/ls')
[526] Fix | Delete
(0, '/bin/ls')
[527] Fix | Delete
>>> subprocess.getstatusoutput('cat /bin/junk')
[528] Fix | Delete
(1, 'cat: /bin/junk: No such file or directory')
[529] Fix | Delete
>>> subprocess.getstatusoutput('/bin/junk')
[530] Fix | Delete
(127, 'sh: /bin/junk: not found')
[531] Fix | Delete
>>> subprocess.getstatusoutput('/bin/kill $$')
[532] Fix | Delete
(-15, '')
[533] Fix | Delete
"""
[534] Fix | Delete
try:
[535] Fix | Delete
data = check_output(cmd, shell=True, universal_newlines=True, stderr=STDOUT)
[536] Fix | Delete
exitcode = 0
[537] Fix | Delete
except CalledProcessError as ex:
[538] Fix | Delete
data = ex.output
[539] Fix | Delete
exitcode = ex.returncode
[540] Fix | Delete
if data[-1:] == '\n':
[541] Fix | Delete
data = data[:-1]
[542] Fix | Delete
return exitcode, data
[543] Fix | Delete
[544] Fix | Delete
def getoutput(cmd):
[545] Fix | Delete
"""Return output (stdout or stderr) of executing cmd in a shell.
[546] Fix | Delete
[547] Fix | Delete
Like getstatusoutput(), except the exit status is ignored and the return
[548] Fix | Delete
value is a string containing the command's output. Example:
[549] Fix | Delete
[550] Fix | Delete
>>> import subprocess
[551] Fix | Delete
>>> subprocess.getoutput('ls /bin/ls')
[552] Fix | Delete
'/bin/ls'
[553] Fix | Delete
"""
[554] Fix | Delete
return getstatusoutput(cmd)[1]
[555] Fix | Delete
[556] Fix | Delete
[557] Fix | Delete
_PLATFORM_DEFAULT_CLOSE_FDS = object()
[558] Fix | Delete
[559] Fix | Delete
[560] Fix | Delete
class Popen(object):
[561] Fix | Delete
""" Execute a child program in a new process.
[562] Fix | Delete
[563] Fix | Delete
For a complete description of the arguments see the Python documentation.
[564] Fix | Delete
[565] Fix | Delete
Arguments:
[566] Fix | Delete
args: A string, or a sequence of program arguments.
[567] Fix | Delete
[568] Fix | Delete
bufsize: supplied as the buffering argument to the open() function when
[569] Fix | Delete
creating the stdin/stdout/stderr pipe file objects
[570] Fix | Delete
[571] Fix | Delete
executable: A replacement program to execute.
[572] Fix | Delete
[573] Fix | Delete
stdin, stdout and stderr: These specify the executed programs' standard
[574] Fix | Delete
input, standard output and standard error file handles, respectively.
[575] Fix | Delete
[576] Fix | Delete
preexec_fn: (POSIX only) An object to be called in the child process
[577] Fix | Delete
just before the child is executed.
[578] Fix | Delete
[579] Fix | Delete
close_fds: Controls closing or inheriting of file descriptors.
[580] Fix | Delete
[581] Fix | Delete
shell: If true, the command will be executed through the shell.
[582] Fix | Delete
[583] Fix | Delete
cwd: Sets the current directory before the child is executed.
[584] Fix | Delete
[585] Fix | Delete
env: Defines the environment variables for the new process.
[586] Fix | Delete
[587] Fix | Delete
universal_newlines: If true, use universal line endings for file
[588] Fix | Delete
objects stdin, stdout and stderr.
[589] Fix | Delete
[590] Fix | Delete
startupinfo and creationflags (Windows only)
[591] Fix | Delete
[592] Fix | Delete
restore_signals (POSIX only)
[593] Fix | Delete
[594] Fix | Delete
start_new_session (POSIX only)
[595] Fix | Delete
[596] Fix | Delete
pass_fds (POSIX only)
[597] Fix | Delete
[598] Fix | Delete
encoding and errors: Text mode encoding and error handling to use for
[599] Fix | Delete
file objects stdin, stdout and stderr.
[600] Fix | Delete
[601] Fix | Delete
Attributes:
[602] Fix | Delete
stdin, stdout, stderr, pid, returncode
[603] Fix | Delete
"""
[604] Fix | Delete
_child_created = False # Set here since __del__ checks it
[605] Fix | Delete
[606] Fix | Delete
def __init__(self, args, bufsize=-1, executable=None,
[607] Fix | Delete
stdin=None, stdout=None, stderr=None,
[608] Fix | Delete
preexec_fn=None, close_fds=_PLATFORM_DEFAULT_CLOSE_FDS,
[609] Fix | Delete
shell=False, cwd=None, env=None, universal_newlines=False,
[610] Fix | Delete
startupinfo=None, creationflags=0,
[611] Fix | Delete
restore_signals=True, start_new_session=False,
[612] Fix | Delete
pass_fds=(), *, encoding=None, errors=None):
[613] Fix | Delete
"""Create new Popen instance."""
[614] Fix | Delete
_cleanup()
[615] Fix | Delete
# Held while anything is calling waitpid before returncode has been
[616] Fix | Delete
# updated to prevent clobbering returncode if wait() or poll() are
[617] Fix | Delete
# called from multiple threads at once. After acquiring the lock,
[618] Fix | Delete
# code must re-check self.returncode to see if another thread just
[619] Fix | Delete
# finished a waitpid() call.
[620] Fix | Delete
self._waitpid_lock = threading.Lock()
[621] Fix | Delete
[622] Fix | Delete
self._input = None
[623] Fix | Delete
self._communication_started = False
[624] Fix | Delete
if bufsize is None:
[625] Fix | Delete
bufsize = -1 # Restore default
[626] Fix | Delete
if not isinstance(bufsize, int):
[627] Fix | Delete
raise TypeError("bufsize must be an integer")
[628] Fix | Delete
[629] Fix | Delete
if _mswindows:
[630] Fix | Delete
if preexec_fn is not None:
[631] Fix | Delete
raise ValueError("preexec_fn is not supported on Windows "
[632] Fix | Delete
"platforms")
[633] Fix | Delete
any_stdio_set = (stdin is not None or stdout is not None or
[634] Fix | Delete
stderr is not None)
[635] Fix | Delete
if close_fds is _PLATFORM_DEFAULT_CLOSE_FDS:
[636] Fix | Delete
if any_stdio_set:
[637] Fix | Delete
close_fds = False
[638] Fix | Delete
else:
[639] Fix | Delete
close_fds = True
[640] Fix | Delete
elif close_fds and any_stdio_set:
[641] Fix | Delete
raise ValueError(
[642] Fix | Delete
"close_fds is not supported on Windows platforms"
[643] Fix | Delete
" if you redirect stdin/stdout/stderr")
[644] Fix | Delete
else:
[645] Fix | Delete
# POSIX
[646] Fix | Delete
if close_fds is _PLATFORM_DEFAULT_CLOSE_FDS:
[647] Fix | Delete
close_fds = True
[648] Fix | Delete
if pass_fds and not close_fds:
[649] Fix | Delete
warnings.warn("pass_fds overriding close_fds.", RuntimeWarning)
[650] Fix | Delete
close_fds = True
[651] Fix | Delete
if startupinfo is not None:
[652] Fix | Delete
raise ValueError("startupinfo is only supported on Windows "
[653] Fix | Delete
"platforms")
[654] Fix | Delete
if creationflags != 0:
[655] Fix | Delete
raise ValueError("creationflags is only supported on Windows "
[656] Fix | Delete
"platforms")
[657] Fix | Delete
[658] Fix | Delete
self.args = args
[659] Fix | Delete
self.stdin = None
[660] Fix | Delete
self.stdout = None
[661] Fix | Delete
self.stderr = None
[662] Fix | Delete
self.pid = None
[663] Fix | Delete
self.returncode = None
[664] Fix | Delete
self.universal_newlines = universal_newlines
[665] Fix | Delete
self.encoding = encoding
[666] Fix | Delete
self.errors = errors
[667] Fix | Delete
[668] Fix | Delete
# Input and output objects. The general principle is like
[669] Fix | Delete
# this:
[670] Fix | Delete
#
[671] Fix | Delete
# Parent Child
[672] Fix | Delete
# ------ -----
[673] Fix | Delete
# p2cwrite ---stdin---> p2cread
[674] Fix | Delete
# c2pread <--stdout--- c2pwrite
[675] Fix | Delete
# errread <--stderr--- errwrite
[676] Fix | Delete
#
[677] Fix | Delete
# On POSIX, the child objects are file descriptors. On
[678] Fix | Delete
# Windows, these are Windows file handles. The parent objects
[679] Fix | Delete
# are file descriptors on both platforms. The parent objects
[680] Fix | Delete
# are -1 when not using PIPEs. The child objects are -1
[681] Fix | Delete
# when not redirecting.
[682] Fix | Delete
[683] Fix | Delete
(p2cread, p2cwrite,
[684] Fix | Delete
c2pread, c2pwrite,
[685] Fix | Delete
errread, errwrite) = self._get_handles(stdin, stdout, stderr)
[686] Fix | Delete
[687] Fix | Delete
# We wrap OS handles *before* launching the child, otherwise a
[688] Fix | Delete
# quickly terminating child could make our fds unwrappable
[689] Fix | Delete
# (see #8458).
[690] Fix | Delete
[691] Fix | Delete
if _mswindows:
[692] Fix | Delete
if p2cwrite != -1:
[693] Fix | Delete
p2cwrite = msvcrt.open_osfhandle(p2cwrite.Detach(), 0)
[694] Fix | Delete
if c2pread != -1:
[695] Fix | Delete
c2pread = msvcrt.open_osfhandle(c2pread.Detach(), 0)
[696] Fix | Delete
if errread != -1:
[697] Fix | Delete
errread = msvcrt.open_osfhandle(errread.Detach(), 0)
[698] Fix | Delete
[699] Fix | Delete
text_mode = encoding or errors or universal_newlines
[700] Fix | Delete
[701] Fix | Delete
self._closed_child_pipe_fds = False
[702] Fix | Delete
[703] Fix | Delete
try:
[704] Fix | Delete
if p2cwrite != -1:
[705] Fix | Delete
self.stdin = io.open(p2cwrite, 'wb', bufsize)
[706] Fix | Delete
if text_mode:
[707] Fix | Delete
self.stdin = io.TextIOWrapper(self.stdin, write_through=True,
[708] Fix | Delete
line_buffering=(bufsize == 1),
[709] Fix | Delete
encoding=encoding, errors=errors)
[710] Fix | Delete
if c2pread != -1:
[711] Fix | Delete
self.stdout = io.open(c2pread, 'rb', bufsize)
[712] Fix | Delete
if text_mode:
[713] Fix | Delete
self.stdout = io.TextIOWrapper(self.stdout,
[714] Fix | Delete
encoding=encoding, errors=errors)
[715] Fix | Delete
if errread != -1:
[716] Fix | Delete
self.stderr = io.open(errread, 'rb', bufsize)
[717] Fix | Delete
if text_mode:
[718] Fix | Delete
self.stderr = io.TextIOWrapper(self.stderr,
[719] Fix | Delete
encoding=encoding, errors=errors)
[720] Fix | Delete
[721] Fix | Delete
self._execute_child(args, executable, preexec_fn, close_fds,
[722] Fix | Delete
pass_fds, cwd, env,
[723] Fix | Delete
startupinfo, creationflags, shell,
[724] Fix | Delete
p2cread, p2cwrite,
[725] Fix | Delete
c2pread, c2pwrite,
[726] Fix | Delete
errread, errwrite,
[727] Fix | Delete
restore_signals, start_new_session)
[728] Fix | Delete
except:
[729] Fix | Delete
# Cleanup if the child failed starting.
[730] Fix | Delete
for f in filter(None, (self.stdin, self.stdout, self.stderr)):
[731] Fix | Delete
try:
[732] Fix | Delete
f.close()
[733] Fix | Delete
except OSError:
[734] Fix | Delete
pass # Ignore EBADF or other errors.
[735] Fix | Delete
[736] Fix | Delete
if not self._closed_child_pipe_fds:
[737] Fix | Delete
to_close = []
[738] Fix | Delete
if stdin == PIPE:
[739] Fix | Delete
to_close.append(p2cread)
[740] Fix | Delete
if stdout == PIPE:
[741] Fix | Delete
to_close.append(c2pwrite)
[742] Fix | Delete
if stderr == PIPE:
[743] Fix | Delete
to_close.append(errwrite)
[744] Fix | Delete
if hasattr(self, '_devnull'):
[745] Fix | Delete
to_close.append(self._devnull)
[746] Fix | Delete
for fd in to_close:
[747] Fix | Delete
try:
[748] Fix | Delete
if _mswindows and isinstance(fd, Handle):
[749] Fix | Delete
fd.Close()
[750] Fix | Delete
else:
[751] Fix | Delete
os.close(fd)
[752] Fix | Delete
except OSError:
[753] Fix | Delete
pass
[754] Fix | Delete
[755] Fix | Delete
raise
[756] Fix | Delete
[757] Fix | Delete
def _translate_newlines(self, data, encoding, errors):
[758] Fix | Delete
data = data.decode(encoding, errors)
[759] Fix | Delete
return data.replace("\r\n", "\n").replace("\r", "\n")
[760] Fix | Delete
[761] Fix | Delete
def __enter__(self):
[762] Fix | Delete
return self
[763] Fix | Delete
[764] Fix | Delete
def __exit__(self, type, value, traceback):
[765] Fix | Delete
if self.stdout:
[766] Fix | Delete
self.stdout.close()
[767] Fix | Delete
if self.stderr:
[768] Fix | Delete
self.stderr.close()
[769] Fix | Delete
try: # Flushing a BufferedWriter may raise an error
[770] Fix | Delete
if self.stdin:
[771] Fix | Delete
self.stdin.close()
[772] Fix | Delete
finally:
[773] Fix | Delete
# Wait for the process to terminate, to avoid zombies.
[774] Fix | Delete
self.wait()
[775] Fix | Delete
[776] Fix | Delete
def __del__(self, _maxsize=sys.maxsize, _warn=warnings.warn):
[777] Fix | Delete
if not self._child_created:
[778] Fix | Delete
# We didn't get to successfully create a child process.
[779] Fix | Delete
return
[780] Fix | Delete
if self.returncode is None:
[781] Fix | Delete
# Not reading subprocess exit status creates a zombi process which
[782] Fix | Delete
# is only destroyed at the parent python process exit
[783] Fix | Delete
_warn("subprocess %s is still running" % self.pid,
[784] Fix | Delete
ResourceWarning, source=self)
[785] Fix | Delete
# In case the child hasn't been waited on, check if it's done.
[786] Fix | Delete
self._internal_poll(_deadstate=_maxsize)
[787] Fix | Delete
if self.returncode is None and _active is not None:
[788] Fix | Delete
# Child is still running, keep us alive until we can wait on it.
[789] Fix | Delete
_active.append(self)
[790] Fix | Delete
[791] Fix | Delete
def _get_devnull(self):
[792] Fix | Delete
if not hasattr(self, '_devnull'):
[793] Fix | Delete
self._devnull = os.open(os.devnull, os.O_RDWR)
[794] Fix | Delete
return self._devnull
[795] Fix | Delete
[796] Fix | Delete
def _stdin_write(self, input):
[797] Fix | Delete
if input:
[798] Fix | Delete
try:
[799] Fix | Delete
self.stdin.write(input)
[800] Fix | Delete
except BrokenPipeError:
[801] Fix | Delete
pass # communicate() must ignore broken pipe errors.
[802] Fix | Delete
except OSError as exc:
[803] Fix | Delete
if exc.errno == errno.EINVAL:
[804] Fix | Delete
# bpo-19612, bpo-30418: On Windows, stdin.write() fails
[805] Fix | Delete
# with EINVAL if the child process exited or if the child
[806] Fix | Delete
# process is still running but closed the pipe.
[807] Fix | Delete
pass
[808] Fix | Delete
else:
[809] Fix | Delete
raise
[810] Fix | Delete
[811] Fix | Delete
try:
[812] Fix | Delete
self.stdin.close()
[813] Fix | Delete
except BrokenPipeError:
[814] Fix | Delete
pass # communicate() must ignore broken pipe errors.
[815] Fix | Delete
except OSError as exc:
[816] Fix | Delete
if exc.errno == errno.EINVAL:
[817] Fix | Delete
pass
[818] Fix | Delete
else:
[819] Fix | Delete
raise
[820] Fix | Delete
[821] Fix | Delete
def communicate(self, input=None, timeout=None):
[822] Fix | Delete
"""Interact with process: Send data to stdin. Read data from
[823] Fix | Delete
stdout and stderr, until end-of-file is reached. Wait for
[824] Fix | Delete
process to terminate.
[825] Fix | Delete
[826] Fix | Delete
The optional "input" argument should be data to be sent to the
[827] Fix | Delete
child process (if self.universal_newlines is True, this should
[828] Fix | Delete
be a string; if it is False, "input" should be bytes), or
[829] Fix | Delete
None, if no data should be sent to the child.
[830] Fix | Delete
[831] Fix | Delete
communicate() returns a tuple (stdout, stderr). These will be
[832] Fix | Delete
bytes or, if self.universal_newlines was True, a string.
[833] Fix | Delete
"""
[834] Fix | Delete
[835] Fix | Delete
if self._communication_started and input:
[836] Fix | Delete
raise ValueError("Cannot send input after starting communication")
[837] Fix | Delete
[838] Fix | Delete
# Optimization: If we are not worried about timeouts, we haven't
[839] Fix | Delete
# started communicating, and we have one or zero pipes, using select()
[840] Fix | Delete
# or threads is unnecessary.
[841] Fix | Delete
if (timeout is None and not self._communication_started and
[842] Fix | Delete
[self.stdin, self.stdout, self.stderr].count(None) >= 2):
[843] Fix | Delete
stdout = None
[844] Fix | Delete
stderr = None
[845] Fix | Delete
if self.stdin:
[846] Fix | Delete
self._stdin_write(input)
[847] Fix | Delete
elif self.stdout:
[848] Fix | Delete
stdout = self.stdout.read()
[849] Fix | Delete
self.stdout.close()
[850] Fix | Delete
elif self.stderr:
[851] Fix | Delete
stderr = self.stderr.read()
[852] Fix | Delete
self.stderr.close()
[853] Fix | Delete
self.wait()
[854] Fix | Delete
else:
[855] Fix | Delete
if timeout is not None:
[856] Fix | Delete
endtime = _time() + timeout
[857] Fix | Delete
else:
[858] Fix | Delete
endtime = None
[859] Fix | Delete
[860] Fix | Delete
try:
[861] Fix | Delete
stdout, stderr = self._communicate(input, endtime, timeout)
[862] Fix | Delete
finally:
[863] Fix | Delete
self._communication_started = True
[864] Fix | Delete
[865] Fix | Delete
sts = self.wait(timeout=self._remaining_time(endtime))
[866] Fix | Delete
[867] Fix | Delete
return (stdout, stderr)
[868] Fix | Delete
[869] Fix | Delete
[870] Fix | Delete
def poll(self):
[871] Fix | Delete
"""Check if child process has terminated. Set and return returncode
[872] Fix | Delete
attribute."""
[873] Fix | Delete
return self._internal_poll()
[874] Fix | Delete
[875] Fix | Delete
[876] Fix | Delete
def _remaining_time(self, endtime):
[877] Fix | Delete
"""Convenience for _communicate when computing timeouts."""
[878] Fix | Delete
if endtime is None:
[879] Fix | Delete
return None
[880] Fix | Delete
else:
[881] Fix | Delete
return endtime - _time()
[882] Fix | Delete
[883] Fix | Delete
[884] Fix | Delete
def _check_timeout(self, endtime, orig_timeout):
[885] Fix | Delete
"""Convenience for checking if a timeout has expired."""
[886] Fix | Delete
if endtime is None:
[887] Fix | Delete
return
[888] Fix | Delete
if _time() > endtime:
[889] Fix | Delete
raise TimeoutExpired(self.args, orig_timeout)
[890] Fix | Delete
[891] Fix | Delete
[892] Fix | Delete
if _mswindows:
[893] Fix | Delete
#
[894] Fix | Delete
# Windows methods
[895] Fix | Delete
#
[896] Fix | Delete
def _get_handles(self, stdin, stdout, stderr):
[897] Fix | Delete
"""Construct and return tuple with IO objects:
[898] Fix | Delete
p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite
[899] Fix | Delete
"""
[900] Fix | Delete
if stdin is None and stdout is None and stderr is None:
[901] Fix | Delete
return (-1, -1, -1, -1, -1, -1)
[902] Fix | Delete
[903] Fix | Delete
p2cread, p2cwrite = -1, -1
[904] Fix | Delete
c2pread, c2pwrite = -1, -1
[905] Fix | Delete
errread, errwrite = -1, -1
[906] Fix | Delete
[907] Fix | Delete
if stdin is None:
[908] Fix | Delete
p2cread = _winapi.GetStdHandle(_winapi.STD_INPUT_HANDLE)
[909] Fix | Delete
if p2cread is None:
[910] Fix | Delete
p2cread, _ = _winapi.CreatePipe(None, 0)
[911] Fix | Delete
p2cread = Handle(p2cread)
[912] Fix | Delete
_winapi.CloseHandle(_)
[913] Fix | Delete
elif stdin == PIPE:
[914] Fix | Delete
p2cread, p2cwrite = _winapi.CreatePipe(None, 0)
[915] Fix | Delete
p2cread, p2cwrite = Handle(p2cread), Handle(p2cwrite)
[916] Fix | Delete
elif stdin == DEVNULL:
[917] Fix | Delete
p2cread = msvcrt.get_osfhandle(self._get_devnull())
[918] Fix | Delete
elif isinstance(stdin, int):
[919] Fix | Delete
p2cread = msvcrt.get_osfhandle(stdin)
[920] Fix | Delete
else:
[921] Fix | Delete
# Assuming file-like object
[922] Fix | Delete
p2cread = msvcrt.get_osfhandle(stdin.fileno())
[923] Fix | Delete
p2cread = self._make_inheritable(p2cread)
[924] Fix | Delete
[925] Fix | Delete
if stdout is None:
[926] Fix | Delete
c2pwrite = _winapi.GetStdHandle(_winapi.STD_OUTPUT_HANDLE)
[927] Fix | Delete
if c2pwrite is None:
[928] Fix | Delete
_, c2pwrite = _winapi.CreatePipe(None, 0)
[929] Fix | Delete
c2pwrite = Handle(c2pwrite)
[930] Fix | Delete
_winapi.CloseHandle(_)
[931] Fix | Delete
elif stdout == PIPE:
[932] Fix | Delete
c2pread, c2pwrite = _winapi.CreatePipe(None, 0)
[933] Fix | Delete
c2pread, c2pwrite = Handle(c2pread), Handle(c2pwrite)
[934] Fix | Delete
elif stdout == DEVNULL:
[935] Fix | Delete
c2pwrite = msvcrt.get_osfhandle(self._get_devnull())
[936] Fix | Delete
elif isinstance(stdout, int):
[937] Fix | Delete
c2pwrite = msvcrt.get_osfhandle(stdout)
[938] Fix | Delete
else:
[939] Fix | Delete
# Assuming file-like object
[940] Fix | Delete
c2pwrite = msvcrt.get_osfhandle(stdout.fileno())
[941] Fix | Delete
c2pwrite = self._make_inheritable(c2pwrite)
[942] Fix | Delete
[943] Fix | Delete
if stderr is None:
[944] Fix | Delete
errwrite = _winapi.GetStdHandle(_winapi.STD_ERROR_HANDLE)
[945] Fix | Delete
if errwrite is None:
[946] Fix | Delete
_, errwrite = _winapi.CreatePipe(None, 0)
[947] Fix | Delete
errwrite = Handle(errwrite)
[948] Fix | Delete
_winapi.CloseHandle(_)
[949] Fix | Delete
elif stderr == PIPE:
[950] Fix | Delete
errread, errwrite = _winapi.CreatePipe(None, 0)
[951] Fix | Delete
errread, errwrite = Handle(errread), Handle(errwrite)
[952] Fix | Delete
elif stderr == STDOUT:
[953] Fix | Delete
errwrite = c2pwrite
[954] Fix | Delete
elif stderr == DEVNULL:
[955] Fix | Delete
errwrite = msvcrt.get_osfhandle(self._get_devnull())
[956] Fix | Delete
elif isinstance(stderr, int):
[957] Fix | Delete
errwrite = msvcrt.get_osfhandle(stderr)
[958] Fix | Delete
else:
[959] Fix | Delete
# Assuming file-like object
[960] Fix | Delete
errwrite = msvcrt.get_osfhandle(stderr.fileno())
[961] Fix | Delete
errwrite = self._make_inheritable(errwrite)
[962] Fix | Delete
[963] Fix | Delete
return (p2cread, p2cwrite,
[964] Fix | Delete
c2pread, c2pwrite,
[965] Fix | Delete
errread, errwrite)
[966] Fix | Delete
[967] Fix | Delete
[968] Fix | Delete
def _make_inheritable(self, handle):
[969] Fix | Delete
"""Return a duplicate of handle, which is inheritable"""
[970] Fix | Delete
h = _winapi.DuplicateHandle(
[971] Fix | Delete
_winapi.GetCurrentProcess(), handle,
[972] Fix | Delete
_winapi.GetCurrentProcess(), 0, 1,
[973] Fix | Delete
_winapi.DUPLICATE_SAME_ACCESS)
[974] Fix | Delete
return Handle(h)
[975] Fix | Delete
[976] Fix | Delete
[977] Fix | Delete
def _execute_child(self, args, executable, preexec_fn, close_fds,
[978] Fix | Delete
pass_fds, cwd, env,
[979] Fix | Delete
startupinfo, creationflags, shell,
[980] Fix | Delete
p2cread, p2cwrite,
[981] Fix | Delete
c2pread, c2pwrite,
[982] Fix | Delete
errread, errwrite,
[983] Fix | Delete
unused_restore_signals, unused_start_new_session):
[984] Fix | Delete
"""Execute program (MS Windows version)"""
[985] Fix | Delete
[986] Fix | Delete
assert not pass_fds, "pass_fds not supported on Windows."
[987] Fix | Delete
[988] Fix | Delete
if not isinstance(args, str):
[989] Fix | Delete
args = list2cmdline(args)
[990] Fix | Delete
[991] Fix | Delete
# Process startup details
[992] Fix | Delete
if startupinfo is None:
[993] Fix | Delete
startupinfo = STARTUPINFO()
[994] Fix | Delete
if -1 not in (p2cread, c2pwrite, errwrite):
[995] Fix | Delete
startupinfo.dwFlags |= _winapi.STARTF_USESTDHANDLES
[996] Fix | Delete
startupinfo.hStdInput = p2cread
[997] Fix | Delete
startupinfo.hStdOutput = c2pwrite
[998] Fix | Delete
startupinfo.hStdError = errwrite
[999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function