Python执行 shell 命令并实时打印输出
生活随笔
收集整理的這篇文章主要介紹了
Python执行 shell 命令并实时打印输出
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
from subprocess import Popen, PIPE, STDOUTdef exe_command(command):"""執(zhí)行 shell 命令并實(shí)時(shí)打印輸出:param command: shell 命令:return: process, exitcode"""print(command)process = Popen(command, stdout=PIPE, stderr=STDOUT, shell=True)with process.stdout:for line in iter(process.stdout.readline, b''):print(line.decode().strip())exitcode = process.wait()return process, exitcode
總結(jié)
以上是生活随笔為你收集整理的Python执行 shell 命令并实时打印输出的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: @1.0.0 dev: `webpack
- 下一篇: Python生成列表的所有子集