import os.path;
import subprocess;
import sys;
fileName = sys.argv[1];
fileNameCompleted = fileName + "_" + "completed";
fileNameStdout = fileName + "_" + "stdout";
with open(fileName) as f:
content = f.readlines()
if os.path.isfile(fileNameCompleted):
fCompleted = open(fileNameCompleted,'a');
else:
fCompleted = open(fileNameCompleted,'w');
fStdout = open(fileNameStdout,'w');
for parameters in content:
print("executing: " + parameters + "\n");
fStdout.write("executing: " + parameters + "\n");
fStdout.flush();
parameters = "hadoop jar btj_controller.jar " + parameters;
p = subprocess.Popen(parameters,bufsize=1024,shell=True,stdout=fStdout,stderr=subprocess.STDOUT);#stdout=subprocess.PIPE,stderr=subprocess.PIPE);
p.wait();
fCompleted.write(parameters + '\n');
fCompleted.flush();
fStdout.close();
fCompleted.close();