o w[eK@spdZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddlm Z ddl Z zddlZWn eyEdZYnwgdZz ddlZddlZdZWneymdZddlZddlZddlZYn0wddlmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)e*gdGd d d e+Z,Gd d d e,Z-Gd dde,Z.erGdddZ/Gddde0Z1ne2eddZ3e4edrej5Z6nej7Z6erdZ8ddZ9ngZ8ddZ9dZ:dZ;dZdd d!d"Z?d#d$Z@dd d%d&ZAGd'd(d(eBZCddddd)d*d+ZDd,d-ZEd.d/ZFd0d1ZGd2d3ZHeHZIdZJGd4d5d5ZKdS)6aSubprocesses with accessible I/O streams This module allows you to spawn processes, connect to their input/output/error pipes, and obtain their return codes. For a complete description of this module see the Python documentation. Main API ======== run(...): Runs a command, waits for it to complete, then returns a CompletedProcess instance. Popen(...): A class for flexibly executing a command in a new process Constants --------- DEVNULL: Special value that indicates that os.devnull should be used PIPE: Special value that indicates a pipe should be created STDOUT: Special value that indicates that stderr should go to stdout Older API ========= call(...): Runs a command, waits for it to complete, then returns the return code. check_call(...): Same as call() but raises CalledProcessError() if return code is not 0 check_output(...): Same as check_call() but returns the contents of stdout instead of a return code getoutput(...): Runs a command in the shell, waits for it to complete, then returns the output getstatusoutput(...): Runs a command in the shell, waits for it to complete, then returns a (exitcode, output) tuple N) monotonic)PopenPIPESTDOUTcall check_callgetstatusoutput getoutput check_outputrunCalledProcessErrorDEVNULLSubprocessErrorTimeoutExpiredCompletedProcessTF)CREATE_NEW_CONSOLECREATE_NEW_PROCESS_GROUPSTD_INPUT_HANDLESTD_OUTPUT_HANDLESTD_ERROR_HANDLESW_HIDESTARTF_USESTDHANDLESSTARTF_USESHOWWINDOWABOVE_NORMAL_PRIORITY_CLASSBELOW_NORMAL_PRIORITY_CLASSHIGH_PRIORITY_CLASSIDLE_PRIORITY_CLASSNORMAL_PRIORITY_CLASSREALTIME_PRIORITY_CLASSCREATE_NO_WINDOWDETACHED_PROCESSCREATE_DEFAULT_ERROR_MODECREATE_BREAKAWAY_FROM_JOB)rrrrrrrr STARTUPINFOrrrrrrrr r!r"c@s eZdZdS)rN)__name__ __module__ __qualname__r'r'!/usr/lib/python3.10/subprocess.pyres rc@<eZdZdZd ddZddZeddZejd dZdS) r zRaised when run() is called with check=True and the process returns a non-zero exit status. Attributes: cmd, returncode, stdout, stderr, output NcC||_||_||_||_dSN) returncodecmdoutputstderr)selfr,r-r.r/r'r'r(__init__o zCalledProcessError.__init__cCs`|jr(|jdkr(z d|jt|j fWSty'd|j|j fYSwd|j|jfS)NrzCommand '%s' died with %r.z)Command '%s' died with unknown signal %d.z.Command '%s' returned non-zero exit status %d.)r,r-signalSignals ValueErrorr0r'r'r(__str__us   zCalledProcessError.__str__cC|jS)z+Alias for output attribute, to match stderrr.r6r'r'r(stdoutszCalledProcessError.stdoutcC ||_dSr+r9r0valuer'r'r(r: NN r$r%r&__doc__r1r7propertyr:setterr'r'r'r(r hs  r c@r)) rzThis exception is raised when the timeout expires while waiting for a child process. Attributes: cmd, output, stdout, stderr, timeout NcCr*r+)r-timeoutr.r/)r0r-rDr.r/r'r'r(r1r2zTimeoutExpired.__init__cCsd|j|jfS)Nz'Command '%s' timed out after %s seconds)r-rDr6r'r'r(r7s zTimeoutExpired.__str__cCr8r+r9r6r'r'r(r:szTimeoutExpired.stdoutcCr;r+r9r<r'r'r(r:r>r?r@r'r'r'r(rs  rc@s,eZdZdddddddddZddZdS)r#rNdwFlags hStdInput hStdOutput hStdError wShowWindowlpAttributeListcCs0||_||_||_||_||_|pdgi|_dS)N handle_listrE)r0rFrGrHrIrJrKr'r'r(r1s zSTARTUPINFO.__init__cCs@|j}d|vrt|d|d<t|j|j|j|j|j|dS)NrLrE) rKcopylistr#rFrGrHrIrJ)r0 attr_listr'r'r(rMs zSTARTUPINFO.copy)r$r%r&r1rMr'r'r'r(r#s  r#c@s2eZdZdZejfddZddZddZeZ dS) HandleFcCs|js d|_||dSdS)NT)closed)r0 CloseHandler'r'r(Closes z Handle.ClosecCs|js d|_t|Std)NTzalready closed)rQintr5r6r'r'r(Detachsz Handle.DetachcCsd|jjt|fS)Nz%s(%d)) __class__r$rTr6r'r'r(__repr__szHandle.__repr__N) r$r%r&rQ_winapirRrSrUrW__del__r'r'r'r(rPs rPPIPE_BUFi PollSelectorcCsdSr+r'r'r'r'r(_cleanupr\c CsZtdurdStddD]}|jtjd}|dur*zt|Wq ty)Yq wq dS)N _deadstate)_active_internal_pollsysmaxsizeremover5)instresr'r'r(r\s cCs*g}tjj}|dkr|dd||S)zgReturn a list of command-line arguments reproducing the current optimization settings in sys.flags.r-O)rbflagsoptimizeappend)argsr=r'r'r("_optim_args_from_interpreter_flags s rpc CsNddddddd}t}|D]\}}ttj|}|dkr'|d ||qtjjr2|d ntjjr;|d tjjrD|d tj d d }tjj }ttdi}d|v}|dkrc| dn|rj| d|rq| d|D] }|d|qs|r| ddD]}||vr||} | dur|} nd|| f} | d| fq|S)z}Return a list of command-line arguments reproducing the current settings in sys.flags, sys.warnoptions and sys._xoptions.dBSvbq)debugdont_write_bytecodeno_siteverbose bytes_warningquietrrjz-Iz-Ez-sN _xoptionsdevzerror::BytesWarningzdefault::BytesWarningdefaultz-W)-Xr~) faulthandler tracemalloc importtime showrefcountutf8Tz%s=%sr) rpitemsgetattrrbrlrnisolatedignore_environment no_user_site warnoptionsr{rdextend) flag_opt_maproflagoptrtwarnoptsr{xoptionsdev_moder=argr'r'r(_args_from_interpreter_flagssT           rrDcOsRt|i|}z|j|dWWdS|1s"wYdS)zRun command with arguments. Wait for command to complete or timeout, then return the returncode attribute. The arguments are the same as for the Popen constructor. Example: retcode = call(["ls", "-l"]) rN)rwaitkill)rD popenargskwargspr'r'r(rQs rcOs:t|i|}|r|d}|dur|d}t||dS)aORun command with arguments. Wait for command to complete. If the exit code was zero then return, otherwise raise CalledProcessError. The CalledProcessError object will have the return code in the returncode attribute. The arguments are the same as for the call function. Example: check_call(["ls", "-l"]) roNr)rgetr )rrretcoder-r'r'r(rbs   rcOsvd|vrtdd|vr/|ddur/|ds&|ds&|ds&|dr)d }nd }||d<t|t|d d |jS) aRun command with arguments and return its output. If the exit code was non-zero it raises a CalledProcessError. The CalledProcessError object will have the return code in the returncode attribute and output in the output attribute. The arguments are the same as for the Popen constructor. Example: >>> check_output(["ls", "-l", "/dev/null"]) b'crw-rw-rw- 1 root root 1, 3 Oct 18 2007 /dev/null\n' The stdout argument is not allowed as it is used internally. To capture standard error in the result, use stderr=STDOUT. >>> check_output(["/bin/sh", "-c", ... "ls -l non_existent_file ; exit 0"], ... stderr=STDOUT) b'ls: non_existent_file: No such file or directory\n' There is an additional optional argument, "input", allowing you to pass a string to the subprocess's stdin. If you use this argument you may not also use the Popen constructor's "stdin" argument, as it too will be used internally. Example: >>> check_output(["sed", "-e", "s/foo/bar/"], ... input=b"when in the course of fooman events\n") b'when in the course of barman events\n' By default, all communication is in bytes, and therefore any "input" should be bytes, and the return value will be bytes. If in text mode, any "input" should be a string, and the return value will be a string decoded according to locale encoding, or by "encoding" if set. Text mode is triggered by setting any of text, encoding, errors or universal_newlines. r:z3stdout argument not allowed, it will be overridden.inputNuniversal_newlinestextencodingerrorsT)r:rDcheck)r5rr rr:)rDrremptyr'r'r(r us#r c@s4eZdZdZd ddZddZeejZ ddZ dS) raEA process that has finished running. This is returned by run(). Attributes: args: The list or str args passed to run(). returncode: The exit code of the process, negative for signals. stdout: The standard output (None if not captured). stderr: The standard error (None if not captured). NcCr*r+)ror,r:r/)r0ror,r:r/r'r'r(r1r2zCompletedProcess.__init__cCshd|jd|jg}|jdur|d|j|jdur(|d|jdt|jd|S)Nz args={!r}zreturncode={!r}z stdout={!r}z stderr={!r}z{}({})z, ) formatror,r:rnr/typer$join)r0ror'r'r(rWs    zCompletedProcess.__repr__cCs |jrt|j|j|j|jdS)z6Raise CalledProcessError if the exit code is non-zero.N)r,r ror:r/r6r'r'r(check_returncodes z!CompletedProcess.check_returncoder?) r$r%r&rAr1rW classmethodtypes GenericAlias__class_getitem__rr'r'r'r(rs   r)rcapture_outputrDrc Os$|dur|ddurtdt|d<|r/|ddus#|ddur'tdt|d<t|d<t|i|L}z |j||d\}}Wn'tyb} z|trY|\| _| _ | d} ~ w|| } |r{| r{t | |j ||dWdn1swYt|j | ||S) a|Run command with arguments and return a CompletedProcess instance. The returned instance will have attributes args, returncode, stdout and stderr. By default, stdout and stderr are not captured, and those attributes will be None. Pass stdout=PIPE and/or stderr=PIPE in order to capture them, or pass capture_output=True to capture both. If check is True and the exit code was non-zero, it raises a CalledProcessError. The CalledProcessError object will have the return code in the returncode attribute, and output & stderr attributes if those streams were captured. If timeout is given, and the process takes too long, a TimeoutExpired exception will be raised. There is an optional argument "input", allowing you to pass bytes or a string to the subprocess's stdin. If you use this argument you may not also use the Popen constructor's "stdin" argument, as it will be used internally. By default, all communication is in bytes, and therefore any "input" should be bytes, and the stdout and stderr will be bytes. If in text mode, any "input" should be a string, and stdout and stderr will be strings decoded according to locale encoding, or by "encoding" if set. Text mode is triggered by setting any of text, encoding, errors or universal_newlines. The other arguments are the same as for the Popen constructor. Nstdinz/stdin and input arguments may not both be used.r:r/z@stdout and stderr arguments may not be used with capture_output.rr.r/)rr5rr communicaterr _mswindowsr:r/rpollr ror) rrrDrrrprocessr:r/excrr'r'r(r s>r cCsg}d}ttj|D]d}g}|r|dd|vpd|vp| }|r'|d|D]1}|dkr5||q)|dkrL|dt|dg}|dq)|rU||g}||q)|rb|||rn|||dq d|S) a Translate a sequence of arguments into a command line string, using the same rules as the MS C runtime: 1) Arguments are delimited by white space, which is either a space or a tab. 2) A string surrounded by double quotation marks is interpreted as a single argument, regardless of white space contained within. A quoted string can be embedded in an argument. 3) A double quotation mark preceded by a backslash is interpreted as a literal double quotation mark. 4) Backslashes are interpreted literally, unless they immediately precede a double quotation mark. 5) If backslashes immediately precede a double quotation mark, every pair of backslashes is interpreted as a literal backslash. If the number of backslashes is odd, the last backslash escapes the next double quotation mark as described in rule 3. F  "\z\"r)maposfsdecodernlenrr)seqresult needquoterbs_bufcr'r'r( list2cmdlines6          rc Csnz t|ddtd}d}Wnty$}z |j}|j}WYd}~nd}~ww|dddkr3|dd}||fS)aReturn (exitcode, output) of executing cmd in a shell. Execute the string 'cmd' in a shell with 'check_output' and return a 2-tuple (status, output). The locale encoding is used to decode the output and process newlines. A trailing newline is stripped from the output. The exit status for the command can be interpreted according to the rules for the function 'wait'. Example: >>> import subprocess >>> subprocess.getstatusoutput('ls /bin/ls') (0, '/bin/ls') >>> subprocess.getstatusoutput('cat /bin/junk') (1, 'cat: /bin/junk: No such file or directory') >>> subprocess.getstatusoutput('/bin/junk') (127, 'sh: /bin/junk: not found') >>> subprocess.getstatusoutput('/bin/kill $$') (-15, '') T)shellrr/rNrg )r rr r.r,)r-dataexitcodeexr'r'r(r\s rcCs t|dS)a%Return output (stdout or stderr) of executing cmd in a shell. Like getstatusoutput(), except the exit status is ignored and the return value is a string containing the command's output. Example: >>> import subprocess >>> subprocess.getoutput('ls /bin/ls') '/bin/ls' r)r)r-r'r'r(r {s r c Cststtds dStjdvrdSzZ.d?d/Z"e/j0e/j1e/j2fd@dAZ3de/j4e/j5e6j7fdBd1Z'dCdDZ8dEd3Z(dFd7Z*dGdHZ9dId9Z+dJd;Z,dKdLZ-dS)QraP Execute a child program in a new process. For a complete description of the arguments see the Python documentation. Arguments: args: A string, or a sequence of program arguments. bufsize: supplied as the buffering argument to the open() function when creating the stdin/stdout/stderr pipe file objects executable: A replacement program to execute. stdin, stdout and stderr: These specify the executed programs' standard input, standard output and standard error file handles, respectively. preexec_fn: (POSIX only) An object to be called in the child process just before the child is executed. close_fds: Controls closing or inheriting of file descriptors. shell: If true, the command will be executed through the shell. cwd: Sets the current directory before the child is executed. env: Defines the environment variables for the new process. text: If true, decode stdin, stdout and stderr using the given encoding (if set) or the system default otherwise. universal_newlines: Alias of text, provided for backwards compatibility. startupinfo and creationflags (Windows only) restore_signals (POSIX only) start_new_session (POSIX only) group (POSIX only) extra_groups (POSIX only) user (POSIX only) umask (POSIX only) pass_fds (POSIX only) encoding and errors: Text mode encoding and error handling to use for file objects stdin, stdout and stderr. Attributes: stdin, stdout, stderr, pid, returncode FrgNTrr')usergroup extra_groupsrrrumaskpipesizec+Cstt|_d|_d|_|durd}t|tstd|dur#d}t|ts,tdt r7|dur6t dn|rC|sCt dt d}| durKt d |d krSt d ||_d|_d|_d|_d|_d|_||_||_||_|dur| durt| t|krtd ||||\}}}}}}t r|dkrt|d }|dkrt|d }|dkrt|d }|p|p|p| |_|jr|durd |_}d|_d|_|jr|dkrd} d}nd} d}!|dur,t t!dst dt|t"rzd dl#}"Wn t$yt dw|"%|j&}!nt|tr|}!n td't(||!d kr,t d|!d}#|durt t!ds=t dt|t"rGt dg}#|D];}$t|$t"rqzd dl#}"Wn t$yet dw|#)|"%|$j&qKt|$tr~|#)|$qKtd't(|$|#D]}%|%d krt d|%qd}&|durt t!dst dt|t"rzd dl*}'Wn t$yt dw|'+|j,}&n t|tr|}&ntd|&d krt d|&zp|dkrt-.|d||_|jrt-j/|jd| ||d |_|dkrt-.|d!||_|jrt-j/|j||d"|_|dkr7t-.|d!||_|jr7t-j/|j||d"|_|0|||||| | | || ||||||||!|#|&||WdSt1d|j|j|jfD]}(z|(2Wqbt3yvYqbw|jsg})|t4kr|))||t4kr|))||t4kr|))|t |d#r|))|j5|)D]#}*zt rt|*t6r|*7nt!2|*Wqt3yYqw)$zCreate new Popen instance.NFrgzbufsize must be an integerzpipesize must be an integerz0preexec_fn is not supported on Windows platformszpass_fds overriding close_fds.Tz2startupinfo is only supported on Windows platformsrz4creationflags is only supported on Windows platformszlCannot disambiguate when both text and universal_newlines are supplied but different. Pass one or the other.localeg?rsetregidz>The 'group' parameter is not supported on the current platformzHThe group parameter cannot be a string on systems without the grp modulez,Group must be a string or an integer, not {}z!Group ID cannot be negative, got setgroupszEThe 'extra_groups' parameter is not supported on the current platformz#Groups must be a list, not a stringzIItems in extra_groups cannot be strings on systems without the grp modulez9Items in extra_groups must be a string or integer, not {}setreuidz=The 'user' parameter is not supported on the current platformzGThe user parameter cannot be a string on systems without the pwd modulez#User must be a string or an integerz User ID cannot be negative, got wb) write_throughline_bufferingrrrb)rr_devnull)8r\ threadingLock _waitpid_lock_input_communication_started isinstancerT TypeErrorrr5warningswarnRuntimeWarningrorr:r/pidr,rrrboolr _get_handlesmsvcrtopen_osfhandlerU text_mode_sigint_wait_secs_closed_child_pipe_fdsrrstrgrp ImportErrorgetgrnamgr_gidrrrnpwdgetpwnampw_uidioopen TextIOWrapper_execute_childfiltercloserrrrPrS)+r0robufsize executablerr:r/ preexec_fn close_fdsrcwdenvr startupinfo creationflagsrestore_signalsstart_new_sessionpass_fdsrrrrrrrrp2creadp2cwritec2preadc2pwriteerrreaderrwritergidrgids extra_group gid_checkuidrfto_closefdr'r'r(r1sV                                            zPopen.__init__cCs@d|jjd|jd|jd}t|dkr|ddd}|S)NPLz...>)rVr$r,ror)r0obj_reprr'r'r(rWs  zPopen.__repr__cCr8r+)rr6r'r'r(rszPopen.universal_newlinescCst||_dSr+)rr)r0rr'r'r(rscCs |||}|ddddS)Nz r )decodereplace)r0rrrr'r'r(_translate_newliness zPopen._translate_newlinescCs|Sr+r'r6r'r'r( __enter__ r]zPopen.__enter__cCs|jr|j|jr|jz0|jr|jW|tkr;|jdkr6z |j|jdWn ty5Ynwd|_dS|dS|tkrf|jdkr]z |j|jdWn ty\Ynwd|_YdS|w)Nrr) r:r r/rKeyboardInterruptr_waitrr)r0exc_typer= tracebackr'r'r(__exit__ s8          zPopen.__exit__cCs\|jsdS|jdur|d|jt|d|j|d|jdur*tdur,t|dSdSdS)Nzsubprocess %s is still running)sourcer^)_child_createdr,rResourceWarningrar`rn)r0_maxsize_warnr'r'r(rY)s   z Popen.__del__cCs"t|dsttjtj|_|jS)Nr)rrr devnullO_RDWRrr6r'r'r( _get_devnull8s zPopen._get_devnullc Cs|r-z|j|Wn"tyYnty,}z|jtjkr!nWYd}~nd}~wwz|jWdSty?YdStyY}z|jtjkrMnWYd}~dSd}~wwr+)rwriteBrokenPipeErrorrerrnoEINVALr )r0rrr'r'r( _stdin_write=s.      zPopen._stdin_writec CsR|jr |r td|durM|jsM|j|j|jgddkrMd}d}|jr*||n|jr8|j}|jn |jrE|j}|j| ||fS|durWt |}nd}z>z | |||\}}Wn-t y|durzt |j||}n|j}d|_z|j|dWtyYwwWd|_nd|_w|j ||d}||fS)a9Interact with process: Send data to stdin and close it. Read data from stdout and stderr, until end-of-file is reached. Wait for process to terminate. The optional "input" argument should be data to be sent to the child process, or None, if no data should be sent to the child. communicate() returns a tuple (stdout, stderr). By default, all communication is in bytes, and therefore any "input" should be bytes, and the (stdout, stderr) will be bytes. If in text mode (indicated by self.text_mode), any "input" should be a string, and (stdout, stderr) will be strings decoded according to locale encoding, or by "encoding" if set. Text mode is triggered by setting any of text, encoding, errors or universal_newlines. z.Cannot send input after starting communicationNrrrT)rr5rr:r/countrBreadr r_time _communicater1minr_remaining_timer2r)r0rrDr:r/endtimesigint_timeoutstsr'r'r(rVsP         zPopen.communicatecCs|S)zSCheck if child process has terminated. Set and return returncode attribute.)rar6r'r'r(rsz Popen.pollcCs|durdS|tS)z5Convenience for _communicate when computing timeouts.N)rE)r0rIr'r'r(rHs zPopen._remaining_timecCsP|durdS|s t|kr&t|j||rd|nd|r"d|ddddS)z2Convenience for checking if a timeout has expired.Nrr)rError)r0rI orig_timeout stdout_seq stderr_seqskip_check_and_raiser'r'r(_check_timeouts zPopen._check_timeoutc Cs||dur t|}z|j|dWSty=|dur%t|j||}n|j}d|_z|j|dWty<Yww)z=Wait for child process to terminate; returns self.returncode.Nrr)rEr2r1rGrrHr)r0rDrIrJr'r'r(rs&   z Popen.waitc Cst|dd}tm}tr,|dkr||j|dkr!||j|dkr+||jn9|dkr?|dkr?||kr?|tj||dkrR|dkrR||krR|tj||dkre|dkre||kre|tj||durp|tj|Wdn1szwYd|_dS)NrrgT) r contextlib ExitStackrcallbackrSrr r) r0rrrrrr devnull_fdstackr'r'r(_close_pipe_fdss*      zPopen._close_pipe_fdsc Csp|dur|dur|durdSd\}}d\}}d\}} |dur:ttj}|dur9tdd\}} t|}t| n4|tkrPtdd\}}t|t|}}n|tkr\t | }nt |t rgt |}nt | }||}|durttj}|durtdd\} }t|}t| n4|tkrtdd\}}t|t|}}n|tkrt | }nt |t rt |}nt | }||}|durttj} | durtdd\} } t| } t| n?|tkrtdd\}} t|t| }} n(|tkr |} n |tkrt | } nt |t r$t |} nt | } || } |||||| fS)|Construct and return tuple with IO objects: p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite N)rgrgrgrgrgrgrgrgr)rX GetStdHandler CreatePiperPrRrr r get_osfhandler=rrTfileno_make_inheritablerrr) r0rr:r/rrrrrr_r'r'r(rsv                  zPopen._get_handlescCs&tt|tddtj}t|S)z2Return a duplicate of handle, which is inheritablerr)rXDuplicateHandleGetCurrentProcessDUPLICATE_SAME_ACCESSrP)r0handlehr'r'r(r]4s  zPopen._make_inheritablecCstdd|DS)zFilter out console handles that can't be used in lpAttributeList["handle_list"] and make sure the list isn't empty. This also removes duplicate handles.cSs,h|]}|d@dkst|tjkr|qS))rX GetFileTypeFILE_TYPE_CHAR).0rbr'r'r( Ds z,Popen._filter_handle_list..)rN)r0rLr'r'r(_filter_handle_list=szPopen._filter_handle_listc!Cs|rJdt|tr n't|tr| rtdt|g}nt|tjr/| r)tdt|g}nt|}|dur   zPopen._posix_spawnc-st|ttfr |g}nt|tjr| rtd|g}nt|}| r6ttdr(dnd}|dg|}r6|d<dur>|dt d|||t rtj r|dur|s|s|dur| d ksc| d kr|d ksk|d kr|d kss|d kr|s|dur|dur|dur|dkr| |||| | | ||| dS}t\}}g}|d kr||t|}|d ks|D]}t|qzz||durg}|D]\}}t|}d |vrtd ||d t|qnd}ttj rf} ntfddt|D} t|}!|!|t|| |tttt|!||| | | |||||||||||||_d|_Wt|nt|w| | | | |||t!}" t"|d}#|"|#7}"|#rat#|"dkrbnqMWt|nt|w|"rzt$|jd\}$}%|$|jkr|%|%ntj&|_'Wn t(yYnwz|")dd \}&}'}(|(*}(Wntyd}&d}'d+t|"}(Ynwt,t-|&*dt.})t/|)t0r|'rt|'d}*|(dk}+|+rd}(|},n|},|*dkrt1|*}(|)|*|(|,|)|(dS)zExecute program (POSIX version)rjgetandroidapilevelz/system/bin/shz/bin/shz-crNrnrgrrd=z!illegal environment variable namec3s$|] }tjt|VqdSr+)rrrrfsencode)rgdirrr'r( s  z'Popen._execute_child..TiP:sSubprocessError0z#Bad exception data from child: {!r}asciinoexecr)2rrrorrprrNrrbru_USE_POSIX_SPAWNrrdirnamerrrndupr rrr5r get_exec_pathsetadd_posixsubprocess fork_execsortedrrTrr7rV bytearrayrDrwaitpid_handle_exitstatusrcr,ChildProcessErrorrr-rrbuiltinsr issubclassrstrerror)-r0rorrrrrrrrrrrrrrrrrr r#rr unix_shellorig_executable errpipe_read errpipe_writelow_fds_to_closelow_fdenv_listkrtexecutable_list fds_to_keep errpipe_datapartrrKexception_name hex_errnoerr_msgchild_exception_type errno_numchild_exec_never_called err_filenamer'rr(r s                          cCs&||r || |_dS|||_dS):All callers to this function MUST hold self._waitpid_lock.N)r,)r0rKwaitstatus_to_exitcode _WIFSTOPPED _WSTOPSIGr'r'r(rKszPopen._handle_exitstatusc Cs|jdurl|jds dSzXz#|jdur|jWW|jS||j|\}}||jkr0||Wn"tyS}z|durA||_n|j|krId|_WYd}~nd}~wwW|j|jSW|j|jS|jw|jS)zCheck if child process has terminated. Returns returncode attribute. This method is called by __del__, so it cannot reference anything outside of the local scope (nor can any methods it calls). NFr)r,racquirereleaserrrr@)r0r__waitpid_WNOHANG_ECHILDrrKer'r'r(raWs4         cCs@zt|j|\}}W||fSty|j}d}Y||fSw)rr)rrrr)r0 wait_flagsrrKr'r'r( _try_waitzs zPopen._try_waitcCsr|jdur|jS|duryt|}d} |jdr\z;|jdur)W|j|jS|tj\}}||jks<|dksr& unregisterrrDrnrrrr/rr)r0rrIrLr:r/ input_viewselectorrDreadykeyeventschunkrr'r'r(rFs                    ,      cCsV|jr#|jdur%d|_||_|dur'|jr)|j|jj|jj|_dSdSdSdSdS)Nr)rrrrencoderr)r0rr'r'r(rs  zPopen._save_inputcCs@||jdur dSz t|j|WdStyYdSw)rN)rr,rrrProcessLookupErrorrr'r'r(r"s  cC|tjdS)z/Terminate the process with SIGTERM N)rr3rr6r'r'r(rBcCr )z*Kill the process with SIGKILL N)rr3SIGKILLr6r'r'r(rGrz Popen.kill)rgNNNNNTFNNNNrTFr'r?)Fr+):r$r%r&rAr7r1rWrrrrrBrrCr/r0r5rbrcrrrYr=rBrrrHrPrrVrrr]rir rXr WAIT_OBJECT_0rrar2rrFrrrrrr WIFSTOPPEDWSTOPSIGrrrr@ECHILDrrr'r'r'r(rs5  |    D H   2<'&   # )f  r)LrArr@rrrr3rbrrrQrrErrr__all__rrXrModuleNotFoundErrorrrrrrrrrrrrrrrrrrrr r!r"r Exceptionrr rr#rTrPrrrr[rSelectSelectorr`r\rrr rprrrr objectrr rrr rr _USE_VFORKrr'r'r'r(s"     P  %     ;4% FI 2