I know there have been similar questions, but the solutions for those didn't help.
I'm writing a python script that calls a command line bash tool; I use subprocess.call() to execute it, like so:
def filter_data(var,rawdir,seq1,seq2,fn,pad=3,hdf='hdf'):
"""
Inputs:
var -> variable you want filtered
rawdir -> the directory where the raw MAS files are stored
seq1 -> first number for which you want the operation executed
seq2 -> last number for which you want the operation executed
pad -> zero-padding for MAS output files (usually either 3 or 6), default = 3
hdf -> whether the files are hdf or h5 (default is currently hdf, to match MAS)
Outputs: the filtered set of files from seq1 to seq2 (inclusive)
"""
# If the filtered-data directory doesn't exist, make it; either way, go there
fildir='/'.join(rawdir.split('/')[0:-2])+'/hf'
if os.path.exists(fildir) == False:
os.mkdir(fildir)
# Main filtering loop
for i in range(seq1,seq2+1,1):
os.chdir(rawdir)
print("### Filtering data for sequence #"+str(i).zfill(pad))
# Call the filter tool
for i in range(len(fvars)):
ivar=fvars[i]
ovar=fildir+ivar[len(ivar)-(len(hdf)+len(var)+2+pad):]
if os.path.isfile(ivar) == True:
subprocess.call(['filter', '-n',str(fn), '-c', '-periodic z', ivar, ovar]) # this is where it's failing
When I run this, I get a syntax error from the filter
tool, but if I paste the exact same command (filter -n $fn -c -periodic z /path/to/input/file/br020.hdf /path/to/output/file/br020.hdf
), it executes properly and outputs the correct file. Anyone know what might be causing this error? Any help is appreciated!