def process_cmd(args_list, line_callback):
popen = subprocess.Popen(args_list, stdout = subprocess.PIPE)
while True:
line = popen.stdout.readline()
if not line:
break
line_callback(line)
# 回调方法,用于处理每行输出的字符串
def line_callback(line_str):
print(line_str)
if __name__ == '__main__':
process_cmd(['df', '-h'], line_callback)
python执行shell,实时输出
最新推荐文章于 2023-10-08 15:50:55 发布