Here is my Flask code. While it is not properly implemented and not working, it at least gives you an idea of what I am trying to do.
@app.route('/runid', methods=['GET','POST'])
def execCmdLocal(cmd):
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=True )
stdout, stderr = proc.communicate()
status = proc.poll()
if status != 0:
print("Failed to execute command %s" % cmd)
return status, stdout, stderr
def runid()
time.sleep(1)
cmdStr = 'cd /root/Dart/log; ls -rt DartRunner*.log | tail -1 '
ret = execCmdLocal(cmdStr)
logName = ret[1].strip()
print('The DartRunner Log generated is: %s'%logName)
with open('/root/Dart/log/' + logName, "r") as fd:
for line in fd:
if 'runId' in line:
runId = line.split()[-1]
print('Run Id: %s'%runId)
break
print runID
return runId
My original Python script is:
import os
from pprint import pprint
import time
def execCmdLocal(cmd):
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=True )
stdout, stderr = proc.communicate()
status = proc.poll()
if status != 0:
print("Failed to execute command %s" % cmd)
return status, stdout, stderr
time.sleep(1)
cmdStr = 'cd /root/Dart/log; ls -rt DartRunner*.log | tail -1 '
ret = execCmdLocal(cmdStr)
#pprint(ret)
logName = ret[1].strip()
print('The DartRunner Log generated is: %s'%logName)
with open(logName, "r") as fd:
for line in fd:
if 'runId' in line:
runId = line.split()[-1]
print('Run Id: %s'%runId)
break;
The output I have is:
The DartRunner Log generated is: DartRunner-2018-06-07-145652.log Run Id: 180607-133
This function is printed when the whole program is started. But I am trying to get it only when I call my restAPI route.
Thanks in advance.