[Tutor] Running DOS jobs in batch

Kent Johnson kent37 at tds.net
Thu Sep 7 11:56:15 CEST 2006


Etrade Griffiths wrote:
> Hi
> 
> I am trying to write a PYTHON script that automates the running of an 
> application program MX200510.EXE under XP Pro via a DOS window.  This file 
> is in directory
> 
> C:\Program Files\CMG\IMEX\2005.10\EXE
> 
> The command line arguments are
> 
> MX200510.EXE -f "temp.dat" -wd "C:\Projects\Vitol\New 
> business\Octon\simulation\full field model\0608"
> 
> My Python script is as follows:
> 
> #
> # Test Python script to submit IMEX jobs
> #
> 
> import os
> 
> #
> # Start of MAIN program
> #
> 
> # Initialisation
> 
> work_dir=r'C:\Projects\Vitol\New business\Octon\simulation\full field 
> model\0608'
> imex_dir=r'C:\Program Files\CMG\IMEX\2005.10\EXE'
> imex_fil='"temp.dat"'
> 
> imex_args=('mx200510.exe','-f',imex_fil,'-wd','"'+work_dir+'"')
> 
> nscen=2
> 
> # Check IMEX directory and files exist
> 
> os.chdir(imex_dir)
> L=os.listdir(imex_dir)
> 
> for item in L:
>      print item
> 
> # Change directory to working directory
> 
> os.chdir(work_dir)
> 
> # Loop over N scenarios
> 
> for n in range(1,nscen):
> 
>      # Spawn IMEX job and wait for completion
> 
>      os.spawnv(os.P_WAIT, imex_dir, imex_args)

I think the second arg to spawnv() should be the name of the program to 
run (MX200510.EXE), not the path to the dir containing MX200510.EXE. The 
parameter is named path but if you look at the examples in the doc it is 
just the name.

Kent

> 
> The output from this script is
> 
> ck9700.dll
> libguide40.dll
> mx200510.exe
> mx200510en.chm
> mx200510sp.chm
> 
> Traceback (most recent call last):
>    File "C:/Projects/Vitol/New business/Octon/simulation/full field 
> model/0608/test_imex.py", line 39, in -toplevel-
>      os.spawnv(os.P_WAIT, imex_dir, imex_args)
> OSError: [Errno 2] No such file or directory



More information about the Tutor mailing list