1 import subprocess
, time
, select
, sys
3 def __init__(self
, command
, shell
=False, *args
, **kwargs
):
4 self
.proc
= subprocess
.Popen(command
, stdout
=subprocess
.PIPE
, stdin
=subprocess
.PIPE
, stderr
=subprocess
.PIPE
, shell
=shell
)
6 def get_exitcode(self
):
9 self
.exitcode
= self
.proc
.wait()
10 self
.proc
.stdout
.close()
11 self
.proc
.stderr
.close()
12 self
.proc
.stdin
.close()
16 def canread(self
, handle
, timeout
=0.0001):
18 if handle
== -1 or self
.exitcode
!= None: return False
19 a
,b
,c
= select
.select([handle
], [], [], timeout
)
24 def read_until(self
, handle
, marker
):
26 while not s
.endswith(marker
):
27 if not self
.canread(handle
, timeout
=1): break
35 return self
.proc
.stdout
37 return self
.proc
.stderr
39 return self
.proc
.stdin
41 return self
.proc
.terminate()