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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值