- 使用os.system函数调用外部程序,这里调用wget下载nginx,要等wget执行完成后,才能继续执行后面的程序
| import os |
| cmd = r'wget http://mirrors.sohu.com/nginx/nginx-1.13.9.zip' |
| os.system(cmd) |
| |
| print('下载完毕') |
| import os |
| |
| version = input('请输入安装包版本:') |
| cmd = fr'd:\tools\wget http://mirrors.sohu.com/nginx/nginx-{version}.zip' |
| os.system(cmd) |
| |
| print('下载完毕') |
- 需求:分析当前C盘可用空间是否不足10%,如果不足,就显示空间告急
- 使用subprocess模块调用外部程序,可以不用等外部程序执行完毕,同时执行自己的程序
| from subprocess import PIPE, Popen |
| |
| |
| proc = Popen( |
| 'fsutil volume diskfree c:', |
| stdin = None, |
| stdout = PIPE, |
| stderr = PIPE, |
| shell=True) |
| |
| |
| |
| outinfo, errinfo = proc.communicate() |
| |
| |
| outinfo = outinfo.decode('gbk') |
| errinfo = errinfo.decode('gbk') |
| print (outinfo) |
| print ('-------------') |
| print (errinfo) |
| |
| outputList = outinfo.splitlines() |
| |
| |
| free = int(outputList[0].split(':')[1].replace(',','').split('(')[0].strip()) |
| |
| |
| total = int(outputList[1].split(':')[1].replace(',','').split('(')[0].strip()) |
| |
| if (free/total < 0.1): |
| print('!! 剩余空间告急!!') |
| else: |
| print('剩余空间足够') |
| from subprocess import Popen |
| proc = Popen( |
| args='wget http://xxxxserver/xxxx.zip', |
| shell=True |
| ) |
| |
| print ('让它下载,我们接下来做其他事情。。。。') |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 字符编码:从基础到乱码解决
· 提示词工程——AI应用必不可少的技术
2022-10-07 整合springboot
2022-10-07 快速失败、非bean入参校验
2022-10-07 分组校验、级联校验、自定义验证规则