Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In ArcGIS, I want to use a Python script (and a standard ArcGIS script tool UI) to call functionality from FWTools.

How would I make the call to FWTools? I tried using os.system(C:\WINDOWS\system32\cmd.exe /K "C:\Program Files\FWTools2.4.7\setfw.bat") which is what the windows shortcut calls, but that is not it. It seems I am probably missing something rather simple, but I can't figure out how to make the right call through python to get FWTools & ogr2ogr operating on the string I pass.

My UI looks like this:

enter image description here

and the pseudo-code behind it is something like:

'ogr2ogr -f "' + outformat + '" "' + outfile + '" "' + infile + '" ' + ogrvars
share|improve this question
You might consider installing the gdal python module (, and then calling the ogr library direct from python. It will be a little lower level, but more direct. – Regan Sarwas Feb 8 '11 at 17:56

I did this a while ago, I'm not sure it is the best way to go, but it worked at the time.

g.fwtools = r"D:\FWTools2.2.8"
# name of translate command
g.cmd = os.path.join(g.fwtools, "bin", "gdal_translate.exe")

def setupfwtools(g):
    Sets the environment variables to access the GDAL tools.
    This allows us to run this script without depending on the
    use running the FW Tools seup batch file first.

args = [g.cmd] + [option1 option2]
os.spawnve(os.P_WAIT, args[0], args, os.environ)
share|improve this answer
up vote 4 down vote accepted

It turns out it was just a silly mistake on my part and forgetting that paths in Python need to be either "\" or "/". The code itself was very simple:

'"C:\\WINDOWS\\system32\\cmd.exe /C" "C:\\Program Files\\FWTools2.4.7\\bin\\ogr2ogr.exe" ' + ogrstring

I have posted the toolbox and python code at:

share|improve this answer
It's okay to mark your own answer accepted. I'm glad you figured it out, I have far too many of those "Doh!" over a single misplaced character myself. :) – matt wilkie Feb 8 '11 at 21:40

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.