subprocess 模块
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 可以与这个子进程进行数据交换
subprocess 模块的更多相关文章
- python学习道路(day7note)(subprocess模块,面向对象)
1.subprocess模块 因为方法较多我就写在code里面了,后面有注释 #!/usr/bin/env python #_*_coding:utf-8_*_ #linux 上调用python脚 ...
- subprocess模块
subprocess的目的就是启动一个新的进程并且与之通信. subprocess模块中只定义了一个类: Popen.可以使用Popen来创建进程,并与进程进行复杂的交互.它的构造函数如下: subp ...
- subprocess模块还提供了很多方便的方法来使得执行 shell 命令
现在你可以看到它正常地处理了转义. 注意 实际上你也可以在shell=False那里直接使用一个单独的字符串作为参数, 但是它必须是命令程序本身,这种做法和在一个列表中定义一个args没什么区别.而如 ...
- Python subprocess模块学习总结
从Python 2.4开始,Python引入subprocess模块来管理子进程,以取代一些旧模块的方法:如 os.system.os.spawn*.os.popen*.popen2.*.comman ...
- Python 线程池的原理和实现及subprocess模块
最近由于项目需要一个与linux shell交互的多线程程序,需要用python实现,之前从没接触过python,这次匆匆忙忙的使用python,发现python确实语法非常简单,功能非常强大,因为自 ...
- python笔记之subprocess模块
python笔记之subprocess模块 [TOC] 从Python 2.4开始,Python引入subprocess模块来管理子进程,以取代一些旧模块的方法:如 os.system.os.spaw ...
- Python学习笔记——基础篇【第六周】——Subprocess模块
执行系统命令 可以执行shell命令的相关模块和函数有: os.system os.spawn* os.popen* --废弃 popen2.* --废弃 com ...
- s14 第5天 时间模块 随机模块 String模块 shutil模块(文件操作) 文件压缩(zipfile和tarfile)shelve模块 XML模块 ConfigParser配置文件操作模块 hashlib散列模块 Subprocess模块(调用shell) logging模块 正则表达式模块 r字符串和转译
时间模块 time datatime time.clock(2.7) time.process_time(3.3) 测量处理器运算时间,不包括sleep时间 time.altzone 返回与UTC时间 ...
- 【转】 Python subprocess模块学习总结
从Python 2.4开始,Python引入subprocess模块来管理子进程,以取代一些旧模块的方法:如 os.system.os.spawn*.os.popen*.popen2.*.comman ...
- Python第十一天 异常处理 glob模块和shlex模块 打开外部程序和subprocess模块 subprocess类 Pipe管道 operator模块 sorted函数 os模块 hashlib模块 platform模块 csv模块
Python第十一天 异常处理 glob模块和shlex模块 打开外部程序和subprocess模块 subprocess类 Pipe管道 operator模块 sorted函 ...
随机推荐
- 数组去重--ES5和ES6
思路:把去重后的数组放到一个空数组中 ES5实现: function uni(arr) { var result = []; for (var i=0;i<arr.length;i++) { i ...
- Python-递归复习-斐波那契-阶乘-52
# 超过最大递归限制的报错# 只要写递归函数,必须要有结束条件. # 返回值# 不要只看到return就认为已经返回了.要看返回操作是在递归到第几层的时候发生的,然后返回给了谁.# 如果不是返回给最外 ...
- CodeForces 719A. Vitya in the Countryside
链接:[http://codeforces.com/group/1EzrFFyOc0/contest/719/problem/A] 题意: 给你一个数列(0, 1, 2, 3, 4, 5, 6, 7, ...
- Redis集群之Jedis的使用
maven依赖 <!-- Redis客户端 --> <dependency> <groupId>redis.clients</groupId> < ...
- Linux 环境变量梳理
Linux中的环境变量有两种:全局变量和局部变量: 定义.访问.删除局部变量 查看全局变量 可以使用printenv或者env命令来打印所有的全局变量. 访问某一项全局变量,可以使用printenv ...
- mysql cpu 100% 满 优化方案
解决MySQL CPU占用100%的经验总结 - karl_han的专栏 - CSDN博客 https://blog.csdn.net/karl_han/article/details/5630782 ...
- WebSocket推送
本篇博客只是记录websocket在自己的项目中的应用,只是记录,不做说明(后来替换为GoEasy了). /** * 握手的设置,这其实是为了获取session */ public class Get ...
- Leetcode SingleNumber I & II & III 136/137/260
SingleNumber I: 题目链接:https://leetcode-cn.com/problems/single-number/ 题意: 给定一个非空整数数组,除了某个元素只出现一次以外,其余 ...
- Java——scoket通讯
Socket 网络上的两个程序通过一个双向的通信连接实现数据的交换,这个连接的一端称为一个socket. Socket是TCP/IP协议通信的抽象层,所以我们还需要了解TCP协议 传输层协议 TCP: ...
- 集合转数组的toArray()和toArray(T[] a)方法
参考:集合转数组的toArray()和toArray(T[] a)方法 1.ArrayList的toArray ArrayList提供了一个将List转为数组的一个非常方便的方法toArray.toA ...