如何读取python脚本中的批处理输出

2024-09-30 18:22:14 发布

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

我正在用python编写一个脚本,它将运行一个批处理文件,批处理完成后将继续执行更多操作。在

我编写了执行批处理的代码,并等待它完成。问题是,如果批处理失败,脚本将不知道它。 如果批处理成功或失败,它将打印到控制台。 我需要您的帮助,以便了解如何使用脚本将批打印读取到控制台

以下是相关代码:

def runAutoFa(self):
    process = Popen([self._batPath], cwd = path, stdin = PIPE)
    process.stdin.write(self._commit)
    time.sleep(2)
    process.stdin.write(self._product)
    time.sleep(2)
    process.stdin.write(self._setupName)
    time.sleep(2)
    process.stdin.close()
    status = process.wait() # The command waits until the batch is finised
    self._logger.flush()
    return status

在继续脚本之前,我需要能够在等待批处理完成的同时读取打印

谢谢!在


Tags: 文件代码self脚本timedefstatusstdin