zoukankan      html  css  js  c++  java
  • 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(' ') 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("-------------------------是否等待下载完成---------------------")

      

  • 相关阅读:
    JZOJ.2117. 【2016-12-30普及组模拟】台风
    团队合作
    长沙游记
    统计
    html....
    OI之路
    三鑫普及组模拟赛
    牛顿迭代法
    台风
    gcd
  • 原文地址:https://www.cnblogs.com/weidaijie/p/14173628.html
Copyright © 2011-2022 走看看