使用subprocess模块调用linux命令

python3
使用subprocess.run()

import subprocess
res=subprocess.run(‘ls -la /opt’,shell=True,check=True,capture_output=True)
print(res.returncode)
print(res.stdout.decode(‘utf-8’))
print(res.stderr.decode(‘utf-8’))

猜你喜欢

转载自blog.csdn.net/weixin_44311188/article/details/85368016