【发布时间】:2012-02-17 03:49:31
【问题描述】:
我为我的应用程序编写了一个简单的 Python 脚本,并预定义了一些快速命令,例如 make 等。
我写了一个运行系统命令的函数(linux):
def runCommand(commandLine):
print('############## Running command: ' + commandLine)
p = subprocess.Popen(commandLine, shell = True, stdout = subprocess.PIPE)
print (p.stdout.read().decode('utf-8'))
除了一些事情之外,一切都很好:
我正在使用 cmake,它的输出是彩色的。有机会在输出中保存颜色吗?
我可以在进程完成后查看输出。例如,make 运行了很长时间,但我只能在完全编译后才能看到输出。怎么异步呢?
【问题讨论】:
标签: python asynchronous stdout subprocess