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?