import os,sys
os.system("echo \"================are you ok ? =====================\"")
def execCmd(cmd):
r = os.popen(cmd)
text = r.read()
r.close()
return text
action = sys.argv[1]
if action=="test":
exeResult = os.popen("cat test1.txt")
results = exeResult.readlines()
exeResult.close()
for result in results:
print(result)
if result == "hello world":
print("hello!")
print("execute finally")
else:
os.system("echo \">>>>>>>>>>>>>No Action Defind\"")
test1.txt 内容
this text from test1
my name is dd
hello world
输出:
================are you ok ? =====================
this text from test1
my name is dd
hello world
execute finally
为什么出不来那个 hello?
1
fy 2016-05-17 13:42:33 +08:00 1
因为还有个 \n ,你把整个 results 都输出看看就知道了。
我承认,你头像的 doge 吸引了我 |
2
tan9le 2016-05-17 13:43:54 +08:00
if result == "hello world\n":
|
4
laoyur 2016-05-17 13:45:08 +08:00
一楼回复速度好快
还有,我这个头像进了此楼感觉好另类 |
7
darkmanno6 2016-05-17 14:43:05 +08:00
if result == "hello world\n":
|
8
darkmanno6 2016-05-17 14:43:45 +08:00
if result == "hello world":
|
9
darkmanno6 2016-05-17 14:44:27 +08:00
上一条错了,应该这样
if result == "hello world\n": |