Q:

How to pass variables from Python to CMD in Windows

I am writing a Python (2.5) script that will search through a folder, grab a specific file, and then pass the file and a command to a CMD shell in Windows.   This needs to be done with the command program.exe /rptcsv <file being created> <file being used>.   Additionally, the .exe HAS to be executed from the C:\Program Files (x86)\Reporter folder, hence the working directory change.   
Here's my problem: I need Python to search for one specific file (fnmatch), and then pass the entire command to a shell.   When this is done correctly, the process runs in the background without launching the GUI. 
I've seen the posts about stdin.  stdout, etc, and I don't need anything piped back- I just need Python to pass the whole thing.   Right now what happens is Python launches the GUI but fails to pass the command complete with variables.   Is there a way to do this? 
I'm still a Python n00b, so please forgive any obvious mistakes.   
MC01 = 'WKST01*.bat'
MC02 = 'WKST02*.bat'
files = os.listdir(FOLDER)

MC01_CMD = fnmatch.filter(files, MC01)
MC01_CSV = "MC01.csv"

exe = ("reporter.exe /rptcsv", MC01_CSV, MC01_CMD)
os.chdir("C:\Program Files (x86)\Reporter")
os.system("exe")

Edit: Earlier in my code, I used os.walk in the FOLDER:
print "Walking directory..."
    for root, dirs, files in os.walk(FOLDER):
        for file in files:
            pathname = os.path.join(root, file)

Because I switched working directories, it's searching for the MC01_CMD file in C:\Program Files (x86)\Reporter and (of course) it's not there.   Is there a way to join pathname and MC01_CMD without creating a new variable so it's got the correct location of MC01_CMD? 

A:

os.system takes a single string as command.  In your case, that is the string "exe".  You need to concatenate the filenames returnd by fnmatch.filter, using " ".join(exe) and then call os.system(command).  Note the missing " in os.system(command). 
For finding the file in a tree, just concatenate the (absolute path of your) base folder of your os.walk call with the basedir and the filename.  You can filter on the filenames during os.walk, too. 
MC01 = 'WKST01*.bat'
MC02 = 'WKST02*.bat'

def collect_files(folder, pattern):
    for basedir, dirs, files in os.walk(folder):
        for file in fnmatch.filter(files, pattern):
                yield os.path.join(folder, basedir, file)

MC01_CMD = collect_files(FOLDER, MC01)
MC01_CSV = "MC01.csv"

command = "reporter.exe /rptcsv "+ MC01_CSV + " " + " ".join(MC01_CMD)
os.chdir("C:\Program Files (x86)\Reporter")
os.system(command)

