python得到命令执行状态,实现回显,代码如下:
try:
if cmd!="":
if huix==True:
if timex == 0:
logps=sups.Popen(cmd,shell=True,stdout=sups.PIPE,close_fds=True)
while logps.poll() is None:
logpsl=logps.stdout.readline()
if logpsl!=None:
self.bjk0.AppendText(logpsl)
else:
break
else:
logps = sups.Popen(cmd,shell=True,stdout=sups.PIPE,close_fds=True)
start = datetime.datetime.now()
while logps.poll() is None:
now = datetime.datetime.now()
if (now-start).seconds > timex:
logps.kill()
self.bjk0.AppendText(" 命令操作已超时。\n")
break
logpsl = logps.stdout.readline()
if logpsl != None:
self.bjk0.AppendText(logpsl)
else:
break
else:
if timex==0:
sups.run(cmd,shell=True)
else:
sups.run(cmd,shell=True,timeout=timex)
except:
self.bjk0.AppendText(' 已取消命令操作。\n')
pass