我写了一个简单的python脚本,它应该在执行时运行“sh”文件。 问题是,脚本运行但它不启动“.sh”文件。当我使用“puffy”手动执行“.sh”文件时,它会完成这项工作,但不会在我使用我的python脚本时执行。那么,为了使它起作用,我需要在脚本中更改哪些内容?Python脚本没有运行“.sh”文件
我会发布下面的方法,以便您可以获得更好的主意。我也使用Python 3.3.5,Oracle Linux 6.8。
调用“.sh”文件的方法,我使用了Popen。
def runPrestage2Stage(self):
import time
time.sleep(60)
reload(Queries)
if "FINISHED" in Queries.statusS2S:
#run batch file
p = Popen(["sh", "/u01/app/Oracle_ODI_11/oracledi/agent/bin/start_prestage2stage_simple.sh"], stdout=PIPE, stderr=PIPE)
stdout, stderr = p.communicate()
print("Prestage2Stage has started")
elif 'ERROR' in Queries.statusS2S:
print("Can not start Prestage Converter, please check runtime status of Stage Converter")
else:
print("Prestage2Stage Converter cannot be started")
主要方法的一部分,即调用方法runPRestage2Stage。
DailyLoadsAutomation.DailyLoads.runPrestage2Stage(self)
load_paraprak_prestage = True
count2 = 0
while load_paraprak_prestage:
reload(Queries)
sleep(300) #waits 300 seconds (5 minutes) and re-checks load status.
if "FINISHED" in Queries.statusPreStage:
load_paraprak_prestage = False
else:
load_paraprak_prestage = True
if count2 == 8:
import sys
sys.exit()
else:
count2 += 1
print("PreStage is finished")
当我运行该脚本,
这将打印“Prestage2Stage已启动”,以及“预安排结束”,因为它是应该的,但它不会运行“.SH”文件。
任何想法是什么错?
你怎么知道它没有运行脚本? – tripleee
我知道它是因为“.sh”文件在ORACLE ODI(数据集成器)中运行作业,我可以检查该作业在数据库中的运行状态。但是,当我执行python脚本时,它并未将ODI作业的运行时状态更改为“正在运行”,因为如果运行“sh”脚本,它应该是这样。 – viganqerimi
尝试运行'['sh','-x',script]',即添加'-x'选项以获得详细的调试输出。 – tripleee