python code执行shell代码
及返回捕捉
import subprocess
cmd='''
pwd
cd ..
pwd
'''
p1=subprocess.Popen('/bin/bash',stdin=subprocess.PIPE, stdout=subprocess.PIPE)
out,err=p1.communicate(cmd.encode('utf-8'))
print out.decode('utf-8')
import subprocess
cmd='date'
out = subprocess.check_output(cmd,shell=True)
outd = out.decode()
while(outd.find('59')<0):
out = subprocess.check_output(cmd,shell=True)
print(out)
outd = out.decode()
print('out')
if(outd.find('59')>=0) :
print('yes')
else:
print('no')