Changeset 628
- Timestamp:
- Oct 17, 2007 9:54:18 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/testScripts/NBosCommand.py
r626 r628 9 9 #------------------------------------------------------------------------ 10 10 def run(cmd) : 11 # p=subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE) 12 # cmdRc=p.wait 13 # cmdRc=p.returncode 14 # print "run rc=" 15 # print cmdRc 16 # cmdStdout=p.stdout.read() 17 # cmdStderr=p.stderr.read() 18 # retVal = { 'returnCode':cmdRc, 'stdout':cmdStdout, 'stderr':cmdStderr } 19 # return retVal 11 p=subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE) 12 cmdStdout,cmdStderr=p.communicate() 13 cmdRc=p.returncode 14 print "run rc=" 15 print cmdRc 16 retVal = { 'returnCode':cmdRc, 'stdout':cmdStdout, 'stderr':cmdStderr } 17 return retVal 20 18 21 19 22 run = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) 20 # run = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) 21 # 22 # # Wait for the process to return 23 # import thread, threading 24 # out, err = [''], [''] 25 # #out, err = "", "" 26 # out_ended, err_ended = threading.Event(), threading.Event() 27 # 28 # def getOutput(output, lines, ended_event) : 29 # #for i in output.readlines() : lines.append(i) 30 # for i in output.readlines() : 31 # lines[0] = lines[0]+i 32 # ended_event.set() 33 # 34 # out_thread = thread.start_new_thread(getOutput, (run.stdout, out, out_ended)) 35 # err_thread = thread.start_new_thread(getOutput, (run.stderr, err, err_ended)) 36 # 37 # out_ended.wait() 38 # err_ended.wait() 39 # 40 # returncode = run.wait() 41 # 42 # retVal = { 'returnCode':returncode, 'stdout':out[0], 'stderr':err[0] } 43 # return retVal 23 44 24 # Wait for the process to return25 import thread, threading26 out, err = [''], ['']27 #out, err = "", ""28 out_ended, err_ended = threading.Event(), threading.Event()29 30 def getOutput(output, lines, ended_event) :31 #for i in output.readlines() : lines.append(i)32 for i in output.readlines() :33 lines[0] = lines[0]+i34 ended_event.set()35 36 out_thread = thread.start_new_thread(getOutput, (run.stdout, out, out_ended))37 err_thread = thread.start_new_thread(getOutput, (run.stderr, err, err_ended))38 39 out_ended.wait()40 err_ended.wait()41 42 returncode = run.wait()43 44 retVal = { 'returnCode':returncode, 'stdout':out[0], 'stderr':err[0] }45 return retVal46
Note: See TracChangeset
for help on using the changeset viewer.