shell_helpers.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:envoy-perf 作者: envoyproxy 项目源码 文件源码
def RunCommand(args, timeout=None, logfile=None):
  """Runs a given command through pexpect.run.

  This function acts as a wrapper over pxpect.run . You can have exception or
  return values based on the exitstatus of the command execution. If exitstatus
   is not zero, then it will return -1, unless you want RuntimeError. If there
  is TIMEOUT, then exception is raised. If events do not match, command's
  output is printed, and -1 is returned.
  Args:
    args: command with arguments as an array
    timeout: timeout for pexpect.run .
    logfile: an opened filestream to write the output
  Raises:
    RuntimeError: Command's exit status is not zero
  Returns:
    Returns -1, if bad exitstatus is not zero and when events do not match
    Otherwise returns 0, if everything is fine
  """
  child = pexpect.spawn(args[0], args=args[1:], timeout=timeout,
                        logfile=logfile)
  child.expect(pexpect.EOF)
  child.close()
  if child.exitstatus:
    print args
    raise RuntimeError(("Error: {}\nProblem running command. "
                        "Exit status: {}").format(child.before,
                                                  child.exitstatus))
  return 0
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号