parameters: (os_cmd, use_shell=False)
docstring: Execute os command and log results.
docstring_summary: Execute os command and log results.
docstring_tokens: Execute os command and log results .
function: def ExecuteCmd(os_cmd, use_shell=False):
    """Execute os command and log results."""
    print "Executing: {0}".format(os_cmd if use_shell else ' '.join(os_cmd))
    process = None
    try:
      process = subprocess.Popen(os_cmd, stdin=None, stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE, bufsize=0, shell=use_shell)
      stdout_stream = fdpexpect.fdspawn(process.stdout)
      stderr_stream = fdpexpect.fdspawn(process.stderr)
      # process.returncode is None until the subprocess completes. Then, it gets
      # filled in with the subprocess exit code.
      while process.returncode is None:
        PipePexpectStreamNonBlocking(stdout_stream, sys.stdout)
        PipePexpectStreamNonBlocking(stderr_stream, sys.stderr)
        process.poll()
      PipePexpectStreamNonBlocking(stdout_stream, sys.stdout)
      PipePexpectStreamNonBlocking(stderr_stream, sys.stderr)
      if process.returncode: # Assume a non-zero exit code means error:
        return "Unable to execute %s" % os_cmd
      return process.returncode
    except Exception, e:
      print "FAILED: %s" % e.__str__()
      raise OsCommandError()
    finally:
      # Terminate sub-process on keyboard interrupt or other exception:
      if process is not None and process.returncode is None:
        process.terminate()
function_tokens: def ExecuteCmd ( os_cmd , use_shell = False ) : print "Executing: {0}" . format ( os_cmd if use_shell else ' ' . join ( os_cmd ) ) process = None try : process = subprocess . Popen ( os_cmd , stdin = None , stdout = subprocess . PIPE , stderr = subprocess . PIPE , bufsize = 0 , shell = use_shell ) stdout_stream = fdpexpect . fdspawn ( process . stdout ) stderr_stream = fdpexpect . fdspawn ( process . stderr ) # process.returncode is None until the subprocess completes. Then, it gets # filled in with the subprocess exit code. while process . returncode is None : PipePexpectStreamNonBlocking ( stdout_stream , sys . stdout ) PipePexpectStreamNonBlocking ( stderr_stream , sys . stderr ) process . poll ( ) PipePexpectStreamNonBlocking ( stdout_stream , sys . stdout ) PipePexpectStreamNonBlocking ( stderr_stream , sys . stderr ) if process . returncode : # Assume a non-zero exit code means error: return "Unable to execute %s" % os_cmd return process . returncode except Exception , e : print "FAILED: %s" % e . __str__ ( ) raise OsCommandError ( ) finally : # Terminate sub-process on keyboard interrupt or other exception: if process is not None and process . returncode is None : process . terminate ( )