#=============================================================================== # This is example logic for Python code that depends upon an external executable # file. If the executable is found on the system path then no problem. # Otherwise, this script attempts to execute the executable in the same # directory where the script is located. # Unfortunately, this logic fails because os.system() fails when both the # executable and the output files are both quoted. Note that the command lines # that this code constructs work just fine at the command prompt. They fail in # os.system(). #=============================================================================== import os.path import sys strCmdName = "ListMetadata" # name of our executable file strOutName = "20071129Metadata.txt" # name of output file # Command line is constructed with both file names quoted for maximum generality. strCmdLine = '"%s" > "%s"' % (strCmdName, strOutName) print "strCmdLine=[%s]" % strCmdLine nRtn = os.system(strCmdLine) # if os.system() fails (which it does) ... if (nRtn != 0): print 'Could not find "%s" on path, looking in script directory' % strCmdName # Create a new command line with a full executable file specification in our script directory. strCmdLine = '"%s" > "%s"' % (os.path.join(os.path.dirname(sys.argv[0]), strCmdName), strOutName) print "strCmdLine=[%s]" % strCmdLine nRtn = os.system(strCmdLine) if (nRtn != 0): raise Exception("Could not locate command")