python使用subprocess执行linux命令

#等待返回,设置callback为True
import subprocess def executeshell_by_call(command, callback=False): """ 执行shell命令 必须加上close_fds=True,否则子进程会一直存在 """ if callback: obj = subprocess.Popen(command, shell=True, close_fds=True, stdout=subprocess.PIPE) lines = obj.stdout.readlines() if len(lines) == 1: lines = str(lines[0], encoding='utf-8').strip('\n') return lines else: return subprocess.Popen(command, shell=True) command = 'wget -O /home/nvd_filesss/nvdcve-1.1-modified.json.zip https://nvd.nist.gov/feeds/json/cve/1.1/nvdcve-1.1-modified.json.zip' executeshell_by_call(command) command = 'unzip -o /home/nvd_filesss/nvdcve-1.1-modified.json.zip' executeshell_by_call(command) file = open(f"/home/nvd_filesss/nvdcve-1.1-modified.json", encoding='utf-8') print("-------------------------是否等待下载完成---------------------")

  

posted @ 2020-12-22 16:13  离人怎挽_wdj  阅读(441)  评论(0编辑  收藏  举报