FAQ
Hello everyone:

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?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100929/e0bf255f/attachment.html>

Search Discussions

  • Steven D'Aprano at Sep 29, 2010 at 8:37 pm

    On Thu, 30 Sep 2010 05:49:53 am Susana Iraiis Delgado Rodriguez wrote:
    Hello everyone:

    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?
    Please don't add extra "bits" around the code you use -- there's no need
    to add asterisks * around the code. Just copy and paste it it into the
    email.

    Can you please copy and paste the exact error message you get? Include
    the full traceback, not just the last line.

    Also, it is a little-known thing that Windows accepts forward slashes as
    well as back-slashes in pathnames. So it is easier to write:

    "C:/Archivos de programa/FWTools2.4.7/bin/ogr2ogr.exe"

    than:

    "C:\\Archivos de programa\\FWTools2.4.7\\bin\\ogr2ogr.exe"



    --
    Steven D'Aprano
  • Alan Gauld at Sep 29, 2010 at 9:18 pm
    "Susana Iraiis Delgado Rodriguez" <susana.delgado_s at utzmg.edu.mx>
    wrote
    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
    more
    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.

    HTH

    --
    Alan Gauld
    Author of the Learn to Program web site
    http://www.alan-g.me.uk/
  • Susana Iraiis Delgado Rodriguez at Sep 30, 2010 at 6:05 pm
    Hello !

    I apoligize for the format of my last message, I didn't realize that putting
    my text in bold format will show those asterisks.
    By the way you're Alan, for the pythom module I first had to read my
    arguments and passed them to the os.system(), it worked. Now when I execute
    this command, in my normal DOS Windows, I must change to another path before
    I run the .exe, I don't know how to tell this to my python module. This is
    my code:

    from dbf import *
    from osgeo import ogr
    import os
    import sys
    def call():
    os.chdir('C:\Python26')
    arg1 = "R1G-GEODESIA2.shp"
    arg2 = "LAYER = 'R1G-GEODESIA'"
    arg4 = "tapalpa_05_plani_point.shp"
    os.system('"C:/Archivos de programa/FWTools2.4.7/setfw"')
    os.system('"C:/Archivos de programa/FWTools2.4.7/bin/ogr2ogr.exe"'+" "
    +"arg1" +" "+ "-where" +" "+ "arg3" +" " +"arg4")
    call()

    If I run it, it shows me the following error:
    Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)]
    on
    win32
    Type "help", "copyright", "credits" or "license" for more information.
    import fw
    Ingresa el nombre para el nuevo mapa
    R1G-GEODESIA2.shp
    Ingresa la condicion
    LAYER = 'R1G-GEODESIA'
    Ingresa el nombre del mapa original
    tapalpa_05_plani_point.shp
    FAILURE:
    Unable to open datasource `arg3' with the following drivers.
    -> ESRI Shapefile
    -> MapInfo File
    -> UK .NTF
    -> SDTS
    -> TIGER
    -> S57
    -> DGN
    -> VRT
    -> REC
    -> Memory
    -> BNA
    -> CSV
    -> NAS
    -> GML
    -> GPX
    -> KML
    -> GeoJSON
    -> Interlis 1
    -> Interlis 2
    -> GMT
    -> SQLite
    -> ODBC
    -> PGeo
    -> OGDI
    -> PostgreSQL
    -> MySQL
    -> XPlane
    -> AVCBin
    -> AVCE00
    -> DXF
    -> Geoconcept
    -> GeoRSS
    -> GPSTrackMaker
    -> VFK
    >>>
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: <http://mail.python.org/pipermail/tutor/attachments/20100930/0c7694b1/attachment.html>
  • Steven D'Aprano at Oct 1, 2010 at 12:06 am

    On Fri, 1 Oct 2010 04:05:08 am Susana Iraiis Delgado Rodriguez wrote:
    Hello !

    I apoligize for the format of my last message, I didn't realize that
    putting my text in bold format will show those asterisks.
    By the way you're Alan, for the pythom module I first had to read my
    arguments and passed them to the os.system(), it worked. Now when I
    execute this command, in my normal DOS Windows, I must change to
    another path before I run the .exe, I don't know how to tell this to
    my python module.
    os.chrdir(path)

    changes to a new path.



    --
    Steven D'Aprano

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouptutor @
categoriespython
postedSep 29, '10 at 7:49p
activeOct 1, '10 at 12:06a
posts5
users3
websitepython.org

People

Translate

site design / logo © 2022 Grokbase