如何关闭子流程.Popen当有

2024-03-28 20:45:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我想用子流程.Popen要运行a_excution,因为a_excution需要几分钟时间,所以我选择Popen而不是call。在

  p = subprocess.Popen(['./a_excution', 'input_file'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  err = p.communicate()[1]
  p.wait()

但问题是,有时input_file是未命中的,因此{}无法工作。我希望python脚本跳过这个错误并继续运行,但是脚本只是停留在这里,既不出错也不继续。在

我怎样才能解决这个问题?如果运行Popen时出错,跳过它。在


Tags: 脚本inputstderrstdout时间流程callfile