#!/apps/python/PRO/bin/python import sys, getopt, os import subprocess loc = 'localdir/' files = [] RUN = [] for f in os.listdir(loc): if f.endswith(".root"): files.append(f) s = f[8:14] RUN.append(int(s)) RUN.sort() of = open('beam_currents.dat','w') for k in RUN: cmd = 'rcnd '+str(k)+' beam_current > bc.dat' os.system(cmd) inf = open('bc.dat','r') line = inf.readline() inf.close() print k, line str1 = str(k)+' '+line of.write(str1)