subprocess模块执行shell命令

subprocess.run

获取当前系统下的一些基本信息

import subprocess

OS_res = subprocess.run('cat /etc/os-release|grep "VERSION="', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
os_version = OS_res.stdout.decode('utf-8')
REP_res = subprocess.run('cat  /etc/apt/sources.list|grep ^deb', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
REP_info = REP_res.stdout.decode('utf-8')
print(os_version)
print(REP_info)
posted @ 2024-04-29 15:15  babyfengfjx  阅读(32)  评论(0编辑  收藏  举报