Thursday, July 26, 2012
Python subprocess.call() and Popen()
import subprocess
#import test
#callcmd = "test.py";
callcmd2 = "AdobePatchInstaller.exe --mode=silent";
callcmd = "full.bat";
callcmdun = "fullun.bat";
def openProcess(callcmd):
try:
process = subprocess.Popen(callcmd,shell=True,stdin=subprocess.PIPE,stdout=subprocess.PIPE, stderr=subprocess.PIPE);
#print process.communicate();
print "----------------";
while process.poll() == None:
line = process.stdout.readline();
print "---Exit code is :"+str(process.poll())+"---"
retcode = process.poll();
if retcode == 0:
print "---install successfully---"
#print subprocess.check_call(callcmd, shell=True,stderr=subprocess.STDOUT);
except Exception,e:
print str(e);
pass
#process.stdin.write("send to test from call");
#print "stdoutdata is : "+str(stdoutdata) + ",stderrdata is : "+str(stderrdata);
openProcess(callcmd);
def callProcess(callcmd):
try:
process = subprocess.call(callcmd,shell=True,stdin=subprocess.PIPE,stdout=subprocess.PIPE, stderr=subprocess.PIPE);
print "---Exit code is :"+str(process)+"---"
if process== 0:
print "---install successfully---"
except Exception,e:
print str(e);
pass
#process.stdin.write("send to test from call");
#print "stdoutdata is : "+str(stdoutdata) + ",stderrdata is : "+str(stderrdata);
callProcess(callcmdun)
Subscribe to:
Posts (Atom)