subprocess 模块
2024-10-17 00:45:35
import subprocess
# 就用来执行系统命令
import os cmd = r'dir D:\上海python全栈4期\day23 | findstr "py"'
# res = subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
# # 从管道中读取数据 管道就是 两个进程通讯的媒介
# # print(type(res.stdout.read().decode("GBK")))
# print(res.stdout.read().decode("GBK"))
# print(res.stderr.read().decode("GBK")) dir = r'dir D:\上海python全栈4期\day23'
find = 'findstr "py"'
"""
stdout 输出管道
stdin 输入管道
stderr 错误管道
"""
res1 = subprocess.Popen(dir,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE) res2 = subprocess.Popen(find,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE,stdin=res1.stdout)
# 从管道中读取数据 管道就是 两个进程通讯的媒介
# print(type(res.stdout.read().decode("GBK")))
# print(res1.stdout.read().decode("GBK"))
print(res2.stderr.read().decode("GBK"),"") # 简单总结 subprocess 主要用于执行系统指令 (启动子进程) 与os.system的不同在于
# subprocess 可以与这个子进程进行数据交换
最新文章
- python 数据类型---列表使用之三
- WPF 无边框透明按钮
- 使用JDK开发WebService
- kafka 搭建与使用
- Party Games
- 【MySQL】通过select语句把一列数据拼接成一条字符串
- Python开发【第七篇】:面向对象 和 python面向对象进阶篇(下)
- 限制窗口拉伸范围——WM_GETMINMAXINFO
- java.net.URLEncode编码 与 URLDecode解码问题
- Log4j配置详解及不同的包(package)下的日志写入到不同的日志文件下
- form表单中enctype属性作用
- Vue组件之全局组件与局部组件
- Python基础理论 - 常用模块
- jQuery 筛选器1
- 公式编辑器MathType基本使用方法总结----应付本科毕业论文完全没问题啦^_^
- Unity5 AssetBundle系列——基本流程
- hyperledger-fabirc1.2-ca-server的生产示例
- postgres配置只能让某一个ip的主机登陆
- Apache-Shiro介绍
- 原型和原型对象(__proto__和prototype)转