python执行终端命令并获得输出结果
-
def shell_exec(cmd: str) -> str:
"""
执行终端命令,输出终端打印结果
:param cmd:
:return:
"""
with os.popen(cmd) as fp:
bf = fp._stream.buffer.read()
out = bf.decode().strip()
return out
def shell_exec(cmd: str) -> str:
"""
执行终端命令,输出终端打印结果
:param cmd:
:return:
"""
with os.popen(cmd) as fp:
bf = fp._stream.buffer.read()
out = bf.decode().strip()
return out