【发布时间】:2016-03-16 04:06:55
【问题描述】:
我对 python 很陌生。需要进一步了解 subprocess.popen。
我有一个执行另一个 python 脚本的脚本。下面是我的脚本将尝试执行另一个脚本的部分。
cmd = ['python %s %s %s %s %s'%(runscript, steps, part_number, serial_number, self.operation)]
p = subprocess.Popen(cmd, shell = True, stdout=subprocess.PIPE)
p.wait()
result = p.stdout.readline()
问题是,被执行的脚本,我必须打印出结果才能通过“result = p.stdout.readline()”读取结果。下面是被执行的脚本
def Main():
if sys.argv[1] == "Initiate" :
doFunc = Functions_obj.Initiate()
if doFunc != 0 :
print doFunc
else :
print "Initiate PASS"
elif sys.argv[1] == "Check" :
getDrive = Functions_obj.initialize()
if getDrive == "NoDevice" :
print getDrive
sys.exit()
doFunc = Functions_obj.Identify_Drive()
if doFunc != 0 :
print doFunc
else :
print "Check PASS"
我的问题是,我想从执行的脚本中“返回”结果而不是打印。我如何使用 subprocess.popen 做到这一点?以及如何使用子进程来获取返回的内容而不是打印的内容
【问题讨论】:
标签: python