[Tutor] Runnig a windows.exe from python

Alan Gauld alan.gauld at btinternet.com
Wed Sep 29 23:18:16 CEST 2010

"Susana Iraiis Delgado Rodriguez" <susana.delgado_s at utzmg.edu.mx> 

> I'm working in a simple python module to run a external command, 
> this
> command is named "ogr2ogr.exe" . When I execute my python script :
> *import os
> def call():
>     os.system(' "C:\\Archivos de 
> programa\\FWTools2.4.7\\bin\\ogr2ogr.exe"
> ')*
> *     raw_input()*
> *call()*
> It runs, but if I want to enter arguments: *ogr2ogr*  to test my 
> .exe, it
> shows me an error *"ogr2ogr is not define", *any suggestion?

You need to read the arfguments before calling the exe. Then create 
the full
command string and pass that tro os.system.

However os.system is a blunt instrument, you will find you have much 
control using the subprocess module which supercedes os.system and
various others ways of executing external programs. It take a wee bit
more effort but the extra control is worth it.

The documentation  has numerous examples and the "Using the OS"
topic of my tutorial has some info too.


Alan Gauld
Author of the Learn to Program web site

More information about the Tutor mailing list