source: branches/testScripts/NBosCommand.py @ 630

Last change on this file since 630 was 629, checked in by jpfasano, 12 years ago

removed print statement

  • Property svn:executable set to *
File size: 1.4 KB
Line 
1#! /usr/bin/env python
2
3import subprocess
4
5#------------------------------------------------------------------------
6# Run a an OS command in another process.
7# Examples might be 'svn checkout', 'make test'.
8# Return: command's return code, stdout messages, & stderr messages
9#------------------------------------------------------------------------
10def run(cmd) :
11  p=subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
12  cmdStdout,cmdStderr=p.communicate()
13  cmdRc=p.returncode
14  retVal = { 'returnCode':cmdRc, 'stdout':cmdStdout, 'stderr':cmdStderr }
15  return retVal
16
17
18#  run = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
19#
20#  # Wait for the process to return
21#  import thread, threading
22#  out, err = [''], ['']
23#  #out, err = "", ""
24#  out_ended, err_ended = threading.Event(), threading.Event()
25#
26#  def getOutput(output, lines, ended_event) :
27#    #for i in output.readlines() : lines.append(i)
28#    for i in output.readlines() :
29#      lines[0] = lines[0]+i
30#    ended_event.set()
31#
32#  out_thread = thread.start_new_thread(getOutput, (run.stdout, out, out_ended))
33#  err_thread = thread.start_new_thread(getOutput, (run.stderr, err, err_ended))
34#
35#  out_ended.wait()
36#  err_ended.wait()
37#
38#  returncode = run.wait()
39#
40#  retVal = { 'returnCode':returncode, 'stdout':out[0], 'stderr':err[0] }
41#  return retVal
42
Note: See TracBrowser for help on using the repository browser.