gpt4 book ai didi

python - 管道批处理文件输出到 Python 脚本

转载 作者:可可西里 更新时间:2023-11-01 14:41:06 29 4
gpt4 key购买 nike

我正在尝试编写一个运行批处理文件的 python 脚本(在 Windows 中),并将该批处理文件的命令行输出作为输入。批处理文件运行我无权访问的进程,并根据这些进程是否成功提供输出。我想从批处理文件中获取这些消息并在 python 脚本中使用它们。有人对如何执行此操作有任何想法吗?

最佳答案

import subprocess

output= subprocess.Popen(
("c:\\bin\\batch.bat", "an_argument", "another_argument"),
stdout=subprocess.PIPE).stdout

for line in output:
# do your work here

output.close()

请注意,最好以“@echo off”开始您的批处理文件。

关于python - 管道批处理文件输出到 Python 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/842120/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com