python执行shell命令

import subprocess


def cmd(command):
subp = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding="utf-8")
return subp.communicate()


res = cmd("ls -l")
res = res[0]
res = res.split("\n")
for line in res:
print(line)
posted on 2022-06-28 01:11  (_OwO_)  阅读(197)  评论(0编辑  收藏  举报