³ò ²ëÑDc @sZdZddkZddkZdddgZyeidƒZWneefj o dZnXgZd„Z d dd „ƒYZ d e fd „ƒYZ ei d djpei djo7[ [ ddd„Z ddd„Zddd„ZnAddd„Z ddd„Zddd„Zeid d gƒd„Zedjo eƒndS(snSpawn a command with pipes to its stdin, stdout, and optionally stderr. The normal os.popen(cmd, mode) call spawns a shell command and provides a file interface to just the input or output of the process depending on whether mode is 'r' or 'w'. This module provides the functions popen2(cmd) and popen3(cmd) which return two or three pipes to the spawned command. iÿÿÿÿNtpopen2tpopen3tpopen4t SC_OPEN_MAXicCs]xVtD]M}|idtiƒdjo+yti|ƒWqUtj oqUXqqWdS(Nt _deadstatei(t_activetpolltsystmaxinttremovet ValueError(tinst((s popen2.pyct_cleanupstPopen3cBsJeZdZdZedd„Zd„Zd„Zdd„Z d„Z RS(swClass representing a child process. Normally instances are created by the factory functions popen2() and popen3().iÿÿÿÿc CsCtƒ||_tiƒ\}}tiƒ\}}|otiƒ\}} ntiƒ|_|idjoLti|dƒti|dƒ|oti| dƒn|i|ƒnti|ƒti |d|ƒ|_ ti|ƒti |d|ƒ|_ |o)ti| ƒti |d|ƒ|_ n d|_ dS(sdThe parameter 'cmd' is the shell command to execute in a sub-process. On UNIX, 'cmd' may be a sequence, in which case arguments will be passed directly to the program without shell intervention (as with os.spawnv()). If 'cmd' is a string it will be passed to the shell (as with os.system()). The 'capturestderr' flag, if true, specifies that the object should capture standard error output of the child process. The default is false. If the 'bufsize' parameter is specified, it specifies the size of the I/O buffers to/from the child process.iiitwtrN(R tcmdtostpipetforktpidtdup2t _run_childtclosetfdopenttochildt fromchildtchilderrtNone( tselfRt capturestderrtbufsizetp2creadtp2cwritetc2preadtc2pwriteterroutterrin((s popen2.pyct__init__%s*     cCsI|idtiƒ|idjo"tdj oti|ƒqEndS(NRi(RRRtstsRRtappend(R((s popen2.pyct__del__Gs cCs‘t|tƒodd|g}nx>tdtƒD]-}yti|ƒWq3tj oq3Xq3Wzti|d|ƒWdtidƒXdS(Ns/bin/shs-ciii( t isinstancet basestringtxrangetMAXFDRRtOSErrortexecvpt_exit(RRti((s popen2.pycROs cCs|idjovy?ti|itiƒ\}}||ijo ||_nWq†tij o!|dj o ||_q‚q†Xn|iS(shReturn the exit status of the child process if it has finished, or -1 if it hasn't finished yet.iN(R'RtwaitpidRtWNOHANGterrorR(RRRR'((s popen2.pycR\s cCsV|idjo?ti|idƒ\}}||ijpt‚||_n|iS(s9Wait for and return the exit status of the child process.i(R'RR2RtAssertionError(RRR'((s popen2.pyctwaitjs  N( t__name__t __module__t__doc__R'tFalseR&R)RRRR6(((s popen2.pycR s"  tPopen4cBseZdZdd„ZRS(iÿÿÿÿcCsâtƒ||_tiƒ\}}tiƒ\}}tiƒ|_|idjoAti|dƒti|dƒti|dƒ|i|ƒnti|ƒti |d|ƒ|_ ti|ƒti |d|ƒ|_ dS(NiiiRR( R RRRRRRRRRRR(RRRR R!R"R#((s popen2.pycR&xs   N(R7R8RRR&(((s popen2.pycR;usitwintos2emxttcCs%ti|||ƒ\}}||fS(s¸Execute the shell command 'cmd' in a sub-process. On UNIX, 'cmd' may be a sequence, in which case arguments will be passed directly to the program without shell intervention (as with os.spawnv()). If 'cmd' is a string it will be passed to the shell (as with os.system()). If 'bufsize' is specified, it sets the buffer size for the I/O pipes. The file objects (child_stdout, child_stdin) are returned.(RR(RRtmodeRR((s popen2.pycRŽscCs+ti|||ƒ\}}}|||fS(sÆExecute the shell command 'cmd' in a sub-process. On UNIX, 'cmd' may be a sequence, in which case arguments will be passed directly to the program without shell intervention (as with os.spawnv()). If 'cmd' is a string it will be passed to the shell (as with os.system()). If 'bufsize' is specified, it sets the buffer size for the I/O pipes. The file objects (child_stdout, child_stdin, child_stderr) are returned.(RR(RRR?RRte((s popen2.pycR˜scCs%ti|||ƒ\}}||fS(s¿Execute the shell command 'cmd' in a sub-process. On UNIX, 'cmd' may be a sequence, in which case arguments will be passed directly to the program without shell intervention (as with os.spawnv()). If 'cmd' is a string it will be passed to the shell (as with os.system()). If 'bufsize' is specified, it sets the buffer size for the I/O pipes. The file objects (child_stdout_stderr, child_stdin) are returned.(RR(RRR?RR((s popen2.pycR¢scCs"t|t|ƒ}|i|ifS(s¸Execute the shell command 'cmd' in a sub-process. On UNIX, 'cmd' may be a sequence, in which case arguments will be passed directly to the program without shell intervention (as with os.spawnv()). If 'cmd' is a string it will be passed to the shell (as with os.system()). If 'bufsize' is specified, it sets the buffer size for the I/O pipes. The file objects (child_stdout, child_stdin) are returned.(R R:RR(RRR?R ((s popen2.pycR¬scCs(t|t|ƒ}|i|i|ifS(sÆExecute the shell command 'cmd' in a sub-process. On UNIX, 'cmd' may be a sequence, in which case arguments will be passed directly to the program without shell intervention (as with os.spawnv()). If 'cmd' is a string it will be passed to the shell (as with os.system()). If 'bufsize' is specified, it sets the buffer size for the I/O pipes. The file objects (child_stdout, child_stdin, child_stderr) are returned.(R tTrueRRR(RRR?R ((s popen2.pycR¶scCst||ƒ}|i|ifS(s¿Execute the shell command 'cmd' in a sub-process. On UNIX, 'cmd' may be a sequence, in which case arguments will be passed directly to the program without shell intervention (as with os.spawnv()). If 'cmd' is a string it will be passed to the shell (as with os.system()). If 'bufsize' is specified, it sets the buffer size for the I/O pipes. The file objects (child_stdout_stderr, child_stdin) are returned.(R;RR(RRR?R ((s popen2.pycRÀsc Cs×tƒt p2tdtg}tD]}||iq#~ƒ‚d}d}tidjo d}n|iƒ}dGHt|ƒ\}}|i |ƒ|i ƒ|i ƒ}|iƒ|jot d||fƒ‚ndGHyt |gƒ\}}}Wnt |ƒ\}}}nX|i |ƒ|i ƒ|i ƒ}|iƒ|jot d||fƒ‚n|i ƒ}|ot d |fƒ‚nxtD]} | iƒqœWtƒtot d ƒ‚nd GHdS( NsActive pipes when test starts tcatsab cd tnttmorestesting popen2...swrote %r read %rstesting popen3...sunexpected %r on stderrs_active not emptysAll OK(R RR5treprRRtnametstripRtwriteRtreadR RR6( t_[1]tcRtteststrtexpectedRRtgotR@R ((s popen2.pyct_testÌsD:         t__main__((R9RRt__all__tsysconfR-tAttributeErrorR RR R R;tplatformRRRtextendROR7(((s popen2.pycss.    V$       '