【问题标题】:How can I port commands.getoutput calls to Python 3?如何将 commands.getoutput 调用移植到 Python 3?
【发布时间】:2012-09-23 11:30:40
【问题描述】:

commands.getoutput() 在当前 Python 2.x 中已被 AFAIR 弃用,并在 Py3k 中被删除。

如何在干净的 Python 3 中获得类似的信息?

【问题讨论】:

    标签: python python-3.x standard-library


    【解决方案1】:

    逐字对应的是subprocess.getoutput。但是,如果命令失败,您几乎总是希望抛出异常,因此使用subprocess.check_output

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-29
      • 2016-04-24
      • 1970-01-01
      • 2020-12-28
      相关资源
      最近更新 更多