executeCommandsFile.py 847 Bytes
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
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();