FAQ
I'm developing a module to execute an external command. The module executes
the command, but in order to make my code useful I have to enter some sql
staments. This is my code:
from dbf import *
from osgeo import ogr
import os
import sys
def call():
print "Ingresa el nombre para el nuevo mapa"
arg1 = "R1G-GEODESIA2.shp"
print arg1
print "Ingresa la condicion"
arg2 = "LAYER = 'R1G-GEODESIA'"
print arg2
print "Ingresa el nombre del mapa original"
arg3 = 'C:/Python26/tapalpa_05_plani_point.shp'
print arg3
os.system('"C:/Archivos de programa/FWTools2.4.7/setfw"')
os.system('"C:/Archivos de programa/FWTools2.4.7/bin/ogr2ogr.exe"'+" "
+"arg1" +" "+ "-where" +" "+ "arg2" +" " +"arg3")
call()
The problem is that when I run the module it throws the error:
Unable to open datasource`arg3' with the following drivers.
ESRI Shapefile
MapInfo File
UK .NTFSDTS
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
Can you help me please?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20101004/e0a276cd/attachment.html>

Search Discussions

  • Norman Khine at Oct 4, 2010 at 2:32 pm

    On Mon, Oct 4, 2010 at 4:04 PM, Susana Iraiis Delgado Rodriguez wrote:
    I'm developing a module to execute an external command. The module executes
    the command, but in order to make my code useful I have to enter some sql
    staments. This is my code:
    from dbf import *
    from osgeo import ogr
    import os
    import sys
    def call():
    ????? print "Ingresa el nombre para el nuevo mapa"
    ????? arg1 = "R1G-GEODESIA2.shp"
    ????? print arg1
    ????? print "Ingresa la condicion"
    ????? arg2 = "LAYER = 'R1G-GEODESIA'"
    ????? print arg2
    ????? print "Ingresa el nombre del mapa original"
    ????? arg3 = 'C:/Python26/tapalpa_05_plani_point.shp'
    ????? print arg3
    ????? os.system('"C:/Archivos de programa/FWTools2.4.7/setfw"')
    ????? os.system('"C:/Archivos de programa/FWTools2.4.7/bin/ogr2ogr.exe"'+" "
    +"arg1" +" "+ "-where" +" "+ "arg2" +" " +"arg3")
    call()
    The?problem?is that when I run the module it throws the error:
    Unable to open datasource`arg3' with the following drivers.
    maybe the path to arg3 is incorrect? did arg1 shapefile load without a problem?
    ESRI Shapefile
    MapInfo File
    UK .NTFSDTS
    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
    Can you help me please?
    _______________________________________________
    Tutor maillist ?- ?Tutor at python.org
    To unsubscribe or change subscription options:
    http://mail.python.org/mailman/listinfo/tutor


    --
    ?u?op ?p?sdn p,u?n? p??o? ??? ??s no? '?u???? s???? ??? pu? '?u??uo?
    ?q s,??? ???
    %>>> "".join( [ {'*':'@','^':'.'}.get(c,None) or
    chr(97+(ord(c)-83)%26) for c in ",adym,*)&uzq^zqf" ] )
  • Steve Willoughby at Oct 4, 2010 at 2:42 pm

    On 04-Oct-10 07:32, Norman Khine wrote:
    On Mon, Oct 4, 2010 at 4:04 PM, Susana Iraiis Delgado Rodriguez
    wrote:
    os.system('"C:/Archivos de programa/FWTools2.4.7/bin/ogr2ogr.exe"'+" "
    +"arg1" +" "+ "-where" +" "+ "arg2" +" " +"arg3")
    You're including the text "arg1" in the command, not the value of the
    arg1 variable. (Likewise for arg2 and arg3). There are some
    unnecessary extra strings in there too. Your os.system() call, slightly
    simplified, is:

    os.system('"C:/Archivos de programa/FWTools2.4.7/bin/ogr2ogr.exe
    "+"arg1" +" -where "+"arg2" +" " +"arg3")

    but what I think you meant was

    os.system('"C:/Archivos de programa/FWTools2.4.7/bin/ogr2ogr.exe "+arg1
    +" -where "+arg2 +" " +arg3)

    There are even better ways to accomplish this task too, but I'm focusing
    on what looks like you ran into with this first.
  • Bill Allen at Oct 4, 2010 at 5:56 pm

    On Mon, Oct 4, 2010 at 9:04 AM, Susana Iraiis Delgado Rodriguez wrote:

    I'm developing a module to execute an external command. The module executes
    the command, but in order to make my code useful I have to enter some sql
    staments. This is my code:
    Question, what database system are you trying to access? Python, via its
    standard library, and also by easily available 3rd party libraries. has
    ample facilities to allow for database access without having to do external
    OS calls. You may have a perfectly valid reason for designing your code
    the way you have, but I thought this was worth asking.

    --Bill
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: <http://mail.python.org/pipermail/tutor/attachments/20101004/527a8197/attachment.html>
  • Susana Iraiis Delgado Rodriguez at Oct 5, 2010 at 1:50 pm
    Hello Norman:

    Thank you for taking the time to answer. I already changed my os.system()
    for your code. I got an error, when I executed this:
    os.system(" 'C:/Archivos de programa/FWTools2.4.7/bin/ogr2ogr.exe ' "+arg1
    +" -where "+arg2 +" " +arg3)
    it throws me that "C:/Archivos" is not recognized as an executable external
    or internal command, programm or file.
    If you really have other opton to fix my problem I'll be thankful because I
    don't have any idea to make this code useful.
    Thank you
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: <http://mail.python.org/pipermail/tutor/attachments/20101005/e6c4bee2/attachment.html>
  • Susana Iraiis Delgado Rodriguez at Oct 5, 2010 at 3:57 pm
    Hello, I already solved the problem, I change all the code, instead of using
    os.system I changed to subprocess.Popen() and it worked fine:

    import shlex, subprocess
    def process():
    print "Ingresa en el siguiente orden:"
    print "Nombre del nuevo mapa.shp Nombre de la capa Nombre del mapa
    original"
    command_line = raw_input()
    args = shlex.split(command_line)
    p = subprocess.Popen(['C:/Archivos de
    programa/FWTools2.4.7/bin/ogr2ogr', args[0], '-where', args[1], args[2]])
    if p:
    print "Mapa generado"
    process()

    Now the user has to enter 3 arguments an finally it worked. I have a
    question, how can I tell the user if p execute ok? because even thouhg I
    entered wrong parameters, it prints "Mapa generado". This line should only
    appears if the arguments are acceptable.

    2010/10/5 Susana Iraiis Delgado Rodriguez <susana.delgado_s at utzmg.edu.mx>
    Hello Norman:

    Thank you for taking the time to answer. I already changed my os.system()
    for your code. I got an error, when I executed this:
    os.system(" 'C:/Archivos de programa/FWTools2.4.7/bin/ogr2ogr.exe '
    "+arg1 +" -where "+arg2 +" " +arg3)
    it throws me that "C:/Archivos" is not recognized as an executable
    external or internal command, programm or file.
    If you really have other opton to fix my problem I'll be thankful because I
    don't have any idea to make this code useful.
    Thank you
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: <http://mail.python.org/pipermail/tutor/attachments/20101005/c18f412b/attachment.html>
  • Norman Khine at Oct 6, 2010 at 1:26 pm
    hello

    On Tue, Oct 5, 2010 at 5:57 PM, Susana Iraiis Delgado Rodriguez
    wrote:
    Hello, I already solved the problem, I change all the code, instead of using
    os.system I changed to subprocess.Popen() and it worked fine:
    import shlex, subprocess
    def process():
    ???? print "Ingresa en el siguiente orden:"
    ???? print "Nombre del nuevo mapa.shp?Nombre de la capa?Nombre del mapa
    original"
    ???? command_line = raw_input()
    ?????args = shlex.split(command_line)
    ???? p = subprocess.Popen(['C:/Archivos de
    programa/FWTools2.4.7/bin/ogr2ogr', args[0], '-where', args[1], args[2]])
    ?if p:
    ??print "Mapa generado"
    process()

    Now the user has to enter 3 arguments an finally it worked. I have a
    question, how can I tell the user if p execute ok? because even thouhg I
    entered wrong parameters, it prints "Mapa generado". This line should only
    appears if the arguments are acceptable.
    it is better to validate the user input arguments before you execute
    the subprocess
    2010/10/5 Susana Iraiis Delgado Rodriguez <susana.delgado_s at utzmg.edu.mx>
    Hello Norman:

    Thank you for taking the time to answer. I already changed my os.system()
    for your code. I got an error, when I executed this:
    os.system(" 'C:/Archivos de programa/FWTools2.4.7/bin/ogr2ogr.exe ' "+arg1
    +" -where "+arg2 +" " +arg3)
    it throws me that "C:/Archivos" ?is not recognized as?an executable
    external or internal command, programm or file.
    If you really have other opton to fix my problem I'll be thankful because
    I don't have any idea to make this code useful.
    Thank you
    _______________________________________________
    Tutor maillist ?- ?Tutor at python.org
    To unsubscribe or change subscription options:
    http://mail.python.org/mailman/listinfo/tutor


    --
    ?u?op ?p?sdn p,u?n? p??o? ??? ??s no? '?u???? s???? ??? pu? '?u??uo?
    ?q s,??? ???
    %>>> "".join( [ {'*':'@','^':'.'}.get(c,None) or
    chr(97+(ord(c)-83)%26) for c in ",adym,*)&uzq^zqf" ] )
  • Walter Prins at Oct 5, 2010 at 4:16 pm
    Thank you for taking the time to answer. I already changed my os.system()
    for your code. I got an error, when I executed this:
    os.system(" 'C:/Archivos de programa/FWTools2.4.7/bin/ogr2ogr.exe ' "+arg1
    +" -where "+arg2 +" " +arg3)
    it throws me that "C:/Archivos" is not recognized as an executable
    external or internal command, programm or file.
    If you really have other opton to fix my problem I'll be thankful because I
    don't have any idea to make this code useful.
    The error message suggests the OS is seeing "C:/Archivos" as the command, as
    opposed to the entire path to ogr2ogr.exe, which implies some quoting
    issue/quotes being stripped off/lost somewhere along the line.

    Walter
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: <http://mail.python.org/pipermail/tutor/attachments/20101005/f4db4f8a/attachment.html>
  • Alan Gauld at Oct 5, 2010 at 6:22 pm
    "Susana Iraiis Delgado Rodriguez" <susana.delgado_s at utzmg.edu.mx>
    wrote
    it throws me that "C:/Archivos" is not recognized as an executable
    external
    or internal command, programm or file.
    You can only use / in paths used by Python.
    You are passing this to the CMD processor via os.system so CMD
    complains.
    It expects / to indicate a command option (/? for example) You need to
    use \ in
    paths passed to CMD.

    HTH,

    Alan G.

    PS I just noticed you switched to subprocess so this is now somewhat
    academic!

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouptutor @
categoriespython
postedOct 4, '10 at 2:04p
activeOct 6, '10 at 1:26p
posts9
users6
websitepython.org

People

Translate

site design / logo © 2022 Grokbase