Using python to call .bat files

James Lockley jpl at global.co.za
Tue Jan 23 18:33:38 EST 2001


> "James" <jpl at global.co.za> schrieb im Newsbeitrag
> > am hoping to use a python script to control a process that at the moment
> > is run by a set of 10 windows batch files.

> import os
> return_code = os.system ('c:\\your\\batch\\file.bat')
>
> If you need to get the output of any of these programs take a look at
> os.popen (filename)

i've been trying os.popen, but it doesn't wait for the set of processes
controlled by the batch file to finish before starting the next
each batch relies on the results from the previous one, so i need the one to
complete before the next starts...


thanks in advance
james

(using python2.0 on winnt4)

this is my best attempt so far...

# calls  batch files
# each bat echoes 'JOB COMPLETE' on finishing; trying to use this as cue
# to start next

import os,string,sys

extcalls=['pyform1.bat','pyreaction.bat']

workpath='D:\\work\\new\\'
for call in extcalls:
        path=os.path.join(workpath,call)
        list=os.popen(path).readlines()
        for line in list:
            if string.find(line,'COMPLETE')>-1:
                    print line
                    continue
       print path





More information about the Python-list mailing list