Piping Batch File output to a Python script
Question: I'm trying to write a python script (in windows) that runs a batch file and
will take the command line output of that batch file as input. The batch file
runs processes that I don't have access to and gives output based on whether
those processes are successful. I'd like to take those messages from the batch
file and use them in the python script. Anyone have any ideas on how to do
this ?


Answer: 
    import subprocess
    
    output= subprocess.Popen(
        ("c:\\bin\\batch.bat", "an_argument", "another_argument"),
        stdout=subprocess.PIPE).stdout
    
    for line in output:
        # do your work here
    
    output.close()
    

Note that it's preferable to start your batch file with "`@echo off`".

