[postgis-users] Calling pgsql2shp.exe via python

Mike Toews mwtoews at gmail.com
Mon Feb 20 16:45:31 PST 2012


On 21 February 2012 13:39, David Quinn <daithiquinn at gmail.com> wrote:
> Thanks for the link, Stefan. After testing out a few approaches this worked:
>
> import subprocess
> subprocess.call(['C:/Program Files (x86)/PostgreSQL/9.1/bin/pgsql2shp.exe',
> '-f', 'D:\testShapefile.shp', '-h localhost', '-u postgres', '-p 5434',
> 'test_db', 'SELECT * FROM  myschema.testquery'])

Watch out for the escaping for Windows paths. You should have one of these:

'D:\\testShapefile.shp'
r'D:\testShapefile.shp' (I prefer this method)
'D:/testShapefile.shp' (I think this works)

As you have it, it will be "D:[tab]estShapefile.shp" with the tab
character. I don't think you are allowed to have a tab character in
Windows path names, but I'm not sure.

-Mike



More information about the postgis-users mailing list