python os.popen.readlines异常_python之read,readline,readlines区别
一个例子展示这三者区别qd_cpu_str=os.popen(r" ps -ef|grep QD|grep -v grep|grep -v cpu|awk '{print $10','$2','$14}'")
print qd_cpu_str.read()
结果:
1 7291 QWorld
1 7297 QDBProxy
1 7310 QGameServer
1 7315 QGateway
1 7325 QCommunity
2 7390 QWorld
2 7397 QDBProxy
2 7403 QGameServer
2 7408 QGateway
2 7412 QCommunity
3 7447 QWorld
3 7454 QDBProxy
3 7475 QGameServer
3 7482 QGateway
3 7486 QCommunity
qd_cpu_str=os.popen(r" ps -ef|grep QD|grep -v grep|grep -v cpu|awk '{print $10','$2','$14}'")
for line in qd_cpu_str.read():
print "line read is: %s" %line
结果:
/usr/bin/python2.6 /data/script/python/pycharm/pycharm_test1/cpu_QD.py
line read is: 1
line read is:
line read is: 7
line read is: 2
line read is: 9
line read is: 1
line read is:
line read is: Q
line read is: W
line read is: o
line read is: r
line read is: l
line read is: d
line read is:
line read is: 1
line read is:
line read is: 7
line read is: 2
line read is: 9
line read is: 7
line read is:
line read is: Q
line read is: D
line read is: B
line read is: P
line read is: r
line read is: o
line read is: x
line read is: y
line read is:
line read is: 1
line read is:
line read is: 7
line read is: 3
line read is: 1
line read is: 0
line read is:
line read is: Q
line read is: G
line read is: a
line read is: m
line read is: e
line read is: S
line read is: e
line read is: r
line read is: v
line read is: e
line read is: r
line read is:
line read is: 1
line read is:
line read is: 7
line read is: 3
line read is: 1
line read is: 5
line read is:
line read is: Q
line read is: G
line read is: a
line read is: t
line read is: e
line read is: w
line read is: a
line read is: y
line read is:
line read is: 1
line read is:
line read is: 7
line read is: 3
line read is: 2
line read is: 5
line read is:
line read is: Q
line read is: C
line read is: o
line read is: m
line read is: m
line read is: u
line read is: n
line read is: i
line read is: t
line read is: y
line read is:
line read is: 2
line read is:
line read is: 7
line read is: 3
line read is: 9
line read is: 0
line read is:
line read is: Q
line read is: W
line read is: o
line read is: r
line read is: l
line read is: d
line read is:
line read is: 2
line read is:
line read is: 7
line read is: 3
line read is: 9
line read is: 7
line read is:
line read is: Q
line read is: D
line read is: B
line read is: P
line read is: r
line read is: o
line read is: x
line read is: y
line read is:
line read is: 2
line read is:
line read is: 7
line read is: 4
line read is: 0
line read is: 3
line read is:
line read is: Q
line read is: G
line read is: a
line read is: m
line read is: e
line read is: S
line read is: e
line read is: r
line read is: v
line read is: e
line read is: r
line read is:
line read is: 2
line read is:
line read is: 7
line read is: 4
line read is: 0
line read is: 8
line read is:
line read is: Q
line read is: G
line read is: a
line read is: t
line read is: e
line read is: w
line read is: a
line read is: y
line read is:
line read is: 2
line read is:
line read is: 7
line read is: 4
line read is: 1
line read is: 2
line read is:
line read is: Q
line read is: C
line read is: o
line read is: m
line read is: m
line read is: u
line read is: n
line read is: i
line read is: t
line read is: y
line read is:
line read is: 3
line read is:
line read is: 7
line read is: 4
line read is: 4
line read is: 7
line read is:
line read is: Q
line read is: W
line read is: o
line read is: r
line read is: l
line read is: d
line read is:
line read is: 3
line read is:
line read is: 7
line read is: 4
line read is: 5
line read is: 4
line read is:
line read is: Q
line read is: D
line read is: B
line read is: P
line read is: r
line read is: o
line read is: x
line read is: y
line read is:
line read is: 3
line read is:
line read is: 7
line read is: 4
line read is: 7
line read is: 5
line read is:
line read is: Q
line read is: G
line read is: a
line read is: m
line read is: e
line read is: S
line read is: e
line read is: r
line read is: v
line read is: e
line read is: r
line read is:
line read is: 3
line read is:
line read is: 7
line read is: 4
line read is: 8
line read is: 2
line read is:
line read is: Q
line read is: G
line read is: a
line read is: t
line read is: e
line read is: w
line read is: a
line read is: y
line read is:
line read is: 3
line read is:
line read is: 7
line read is: 4
line read is: 8
line read is: 6
line read is:
line read is: Q
line read is: C
line read is: o
line read is: m
line read is: m
line read is: u
line read is: n
line read is: i
line read is: t
line read is: y
line read is:
Process finished with exit code 0
qd_cpu_str=os.popen(r" ps -ef|grep QD|grep -v grep|grep -v cpu|awk '{print $10','$2','$14}'")
for line in qd_cpu_str.readline():
print "line readline is: %s" %line
结果:
/usr/bin/python2.6 /data/script/python/pycharm/pycharm_test1/cpu_QD.py
line readline is: 1
line readline is:
line readline is: 7
line readline is: 2
line readline is: 9
line readline is: 1
line readline is:
line readline is: Q
line readline is: W
line readline is: o
line readline is: r
line readline is: l
line readline is: d
line readline is:
Process finished with exit code 0
qd_cpu_str=os.popen(r" ps -ef|grep QD|grep -v grep|grep -v cpu|awk '{print $10','$2','$14}'")
for line in qd_cpu_str.readlines():
print "line readlines is: %s" %line
/usr/bin/python2.6 /data/script/python/pycharm/pycharm_test1/cpu_QD.py
line readlines is: 1 7291 QWorld
line readlines is: 1 7297 QDBProxy
line readlines is: 1 7310 QGameServer
line readlines is: 1 7315 QGateway
line readlines is: 1 7325 QCommunity
line readlines is: 2 7390 QWorld
line readlines is: 2 7397 QDBProxy
line readlines is: 2 7403 QGameServer
line readlines is: 2 7408 QGateway
line readlines is: 2 7412 QCommunity
line readlines is: 3 7447 QWorld
line readlines is: 3 7454 QDBProxy
line readlines is: 3 7475 QGameServer
line readlines is: 3 7482 QGateway
line readlines is: 3 7486 QCommunity
Process finished with exit code 0
python os.popen.readlines异常_python之read,readline,readlines区别相关推荐
- python中readlines方法_Python中read(),readline(),readlines()使用详解
# python3.7 1.read()会读取文件的全部内容,read(size)方法,每次最多读取size个字节的内容,返回字符串. #a.txt 第一行为abc #a.txt 第二行为a12 ...
- python os.popen()方法(用于从一个命令打开一个管道)
描述 os.popen() 方法用于从一个命令打开一个管道. 在Unix,Windows中有效 os.popen(command[, mode[, bufsize]]) command -- 使用的命 ...
- python os.popen.readlines异常_python中执行sed命令操作源文件时出现错误
我想在python中执行一个sed命令,第一种方法直接指定文件时,可以正确输出结果,但是第二种我打开文件操作的时候就有问题,不知道什么原因,求高手解答?(1)>>>sedcmd=&q ...
- python中popen转变时区_python中的subprocess.Popen()使用
从python2.4版本开始,可以用subprocess这个模块来产生子进程,并连接到子进程的标准输入/输出/错误中去,还可以得到子进程的返回值. subprocess意在替代其他几个老的模块或者函数 ...
- python中popen的用法_python中的subprocess.Popen()使用
从python2.4版本开始,可以用subprocess这个模块来产生子进程,并连接到子进程的标准输入/输出/错误中去,还可以得到子进程的返回值. subprocess意在替代其他几个老的模块或者函数 ...
- python 调用外部程序 终端异常_python调用外部命令
python调用外部命令 os.system: 输出在终端上,捕捉不到 os.popen: 只能捕捉到标准输出,捕捉不到标准错误输出 os.popen2: 返回2个对象,一个是标准输入,一个是标准输出 ...
- 【转】python os.popen 超时问题
python 版本 2.5.4 (在高版本python中提倡使用 subprocess.Popen 取代 os.popen) os.popen 会出现过长时间等待导致阻塞问题, 解决方法如下: [py ...
- python os popen_【转】python os.popen 超时问题
python 版本 2.5.4 (在高版本python中提倡使用 subprocess.Popen 取代 os.popen) os.popen 会出现过长时间等待导致阻塞问题, 解决方法如下: [py ...
- python文件不存在异常_Python基础知识:文件和异常
1.相对路径:如果文件和程序在同一文件夹内,可不用路径:如果文件在程序所在文件夹下一级文件夹中,只需添加下一级文件夹名称即可: 在Linux和OS系统中:文件路径中使用斜杠(/) 在Windows系统 ...
最新文章
- 这些名言都是有后半句的,以前都按前半句理解,太坑人!
- 阿里云将增设马来西亚数据中心 中国技术获赞
- c++学习02——queue
- getcwd和pwd为什么不一样_农村医保,为什么每个地区收费不一样?
- Java50道经典习题-程序18 乒乓球赛
- android 获取编译日期,flutter学习笔记(2)android编译,以及如何加快首次编译时间。...
- JavaScript算法(实例八)递归计算每个月的兔子总数【斐波那契数列】
- mkdir 创建目录
- 七、MySql-锁与事物
- python扩展取值范围_python 数据库取值范围内
- 计算机操作系统详细学习笔记(四):设备管理 —— I/O 管理
- Microsoft Office2010 安装包和安装方法
- STM32F103C8T6 红外测距模块测量距离(SHARP GP2Y0A21YK0F)使用CubeMx生成HAL库(ADC)
- 相爱相杀:移动联通IT支撑回忆录(十四)
- word文字上下间距怎么调_word上下文字间距 word字体上下间距怎么调整
- 微信小程序返回Qcloud\\Cos\\Exception\\NoSuchBucketException: Cos Error Code: NoSuchBucket, Status Code: 404
- 怎样破解网页禁用鼠标右键
- 微信大会有哪些看点?
- 目标检测中的precision,recall,AP,mAP计算详解
- 一发入魂!15分钟让你快速入门Python
热门文章
- ChatGPT 的 AskYourPDF 插件所需链接如何获取?
- 一篇HITSZ的究极情况_个人向
- 家庭教育三书-阅读摘要
- python异步爬虫协程的使用学习笔记
- win7更新_微软停止更新 Win7,除了安全隐患,你也许还关心这四个问题。
- linux--代码对比工具Meld Diff
- 真无线蓝牙耳机哪个牌子性价比高?千元内真无线耳机推荐
- 百万富翁c语言题目,谁是百万富翁题目答案是什么 谁是百万富翁全部答案汇总...
- IPv4、IPv6地址、组播地址及子网子划分详解一
- tensorflow手机端模型压缩