mò %U²Ic@sTdZdkZdkZdddgZyeidƒZWneefj o dZnXgZd„Z dfd „ƒYZ d e fd „ƒYZ ei d d jpei djo7[ [ ddd„Z ddd„Zddd„ZnAddd„Z ddd„Zddd„Zeidd 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. Ntpopen2tpopen3tpopen4t SC_OPEN_MAXicCs xtD]}|iƒqWdS(N(t_activetinsttpoll(R((t#/data/zmath/lib/python2.4/popen2.pyt_cleanupstPopen3cBs>tZdZdZedd„Zd„Zd„Zd„ZRS(swClass representing a child process. Normally instances are created by the factory functions popen2() and popen3().iÿÿÿÿc CsGtƒtiƒ\}}tiƒ\} }|otiƒ\}}nti ƒ|_ |i djoLti |dƒti |dƒ|oti |dƒn|i|ƒnti|ƒti|d|ƒ|_ti|ƒti| d|ƒ|_|o)ti|ƒti|d|ƒ|_n d|_ti|ƒ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(Rtostpipetp2creadtp2cwritetc2preadtc2pwritet capturestderrterroutterrintforktselftpidtdup2t _run_childtcmdtclosetfdopentbufsizettochildt fromchildtchilderrtNoneRtappend( RRRRRRRRRR((Rt__init__s,     cCs‘t|tƒodd|g}nx>tdtƒD]-}yti|ƒWq3tj oq3Xq3Wzti |d|ƒWdti dƒXdS(Ns/bin/shs-ciii( t isinstanceRt basestringtxrangetMAXFDtiR RtOSErrortexecvpt_exit(RRR(((RRAs cCs€|idjoiyLti|itiƒ\}}||ijo||_ti|ƒnWqytij oqyXn|iS(shReturn the exit status of the child process if it has finished, or -1 if it hasn't finished yet.iN( RtstsR twaitpidRtWNOHANGRtremoveterror(RRR,((RRNs  cCs`|idjoIti|idƒ\}}||ijo||_ti|ƒqYn|iS(s9Wait for and return the exit status of the child process.iN(RR,R R-RRR/(RRR,((Rtwait[s ( t__name__t __module__t__doc__R,tFalseR#RRR1(((RR s " tPopen4cBstZdZdd„ZRS(NiÿÿÿÿcCsætƒtiƒ\}}tiƒ\}}tiƒ|_ |i djoAti |dƒti |dƒti |dƒ|i |ƒnti |ƒti|d|ƒ|_ti |ƒti|d|ƒ|_ti|ƒdS(NiiiR R (RR R RRRRRRRRRRRRRRRRR"(RRRRRRR((RR#hs  (R2R3R!R R#(((RR6esitwintos2emxiÿÿÿÿttcCs%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.N(R RRtmodeRR R (RRR:R R ((RR~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.N(R RRR:RR R te(RRR:R;R R ((RRˆ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.N(R RRR:RR R (RRR:R R ((RR’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.N(R RR5RRRR(RRR:R((RRœ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.N(R RtTrueRRRRR (RRR:R((RR¦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.N(R6RRRRR(RRR:R((RR°scCsd}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[Wtot d ƒ‚nd GHdS( Ntcatsab cd tnttmorestesting popen2...swrote %r read %rstesting popen3...sunexpected %r on stderrs_active not emptysAll OK(RtteststrR tnametstriptexpectedRR R twriteRtreadtgott ValueErrorRR;RRR1(R;R@RR RR RCRF((Rt_test¼s>         t__main__(R4R tsyst__all__tsysconfR'tAttributeErrorRGRRR R6tplatformRRRtextendRHR2( RKR'RRR RJRR6RRRHR ((Rt?s.    L$       #