[postgis-users] Calling pgsql2shp.exe via python
I'm trying to call the pgsql2shp.exe function using python, as I would like to be able to loop through some tables. What I've tried doing is the following: import os os.system('start C:\Program Files (x86)\PostgreSQL\9.1\bin\pgsql2shp.exe -f D:\testShapefile.shp -h localhost -u postgres -p 5432 test_db SELECT * FROM myschema.testquery') When I paste the line: C:\Program Files (x86)\PostgreSQL\9.1\bin\pgsql2shp.exe -f D:\testShapefile.shp -h localhost -u postgres -p 5432 test_db SELECT * FROM myschema.testquery it produces a shapefile without a problem. However, my python script flashes open a CMD terminal, but it disappears before I see what is happening and does not produce any output. I'm using PostGIS 2.0, Windows 7, and Python 2.6.5. If there is an alternative approach to python for this, I will happily try it out. (I hope this question is not too off-topic!) Thanks, David ___ postgis-users mailing list postgis-users@postgis.refractions.net http://postgis.refractions.net/mailman/listinfo/postgis-users
Re: [postgis-users] Calling pgsql2shp.exe via python
Your quotes are misplaced, try os.system('start C:\Program Files (x86)\PostgreSQL\9.1\bin\pgsql2shp.exe -f D:\testShapefile.shp -h localhost -u postgres -p 5432 test_db SELECT * FROM myschema.testquery') On Mon, Feb 20, 2012 at 2:24 PM, David Quinn daithiqu...@gmail.com wrote: I'm trying to call the pgsql2shp.exe function using python, as I would like to be able to loop through some tables. What I've tried doing is the following: import os os.system('start C:\Program Files (x86)\PostgreSQL\9.1\bin\pgsql2shp.exe -f D:\testShapefile.shp -h localhost -u postgres -p 5432 test_db SELECT * FROM myschema.testquery') When I paste the line: C:\Program Files (x86)\PostgreSQL\9.1\bin\pgsql2shp.exe -f D:\testShapefile.shp -h localhost -u postgres -p 5432 test_db SELECT * FROM myschema.testquery it produces a shapefile without a problem. However, my python script flashes open a CMD terminal, but it disappears before I see what is happening and does not produce any output. I'm using PostGIS 2.0, Windows 7, and Python 2.6.5. If there is an alternative approach to python for this, I will happily try it out. (I hope this question is not too off-topic!) Thanks, David ___ postgis-users mailing list postgis-users@postgis.refractions.net http://postgis.refractions.net/mailman/listinfo/postgis-users ___ postgis-users mailing list postgis-users@postgis.refractions.net http://postgis.refractions.net/mailman/listinfo/postgis-users
Re: [postgis-users] Calling pgsql2shp.exe via python
I did try that and got the following error message: Windows cannot find '-f'. Make sure that you typed the name correctly, and then try again. On Mon, Feb 20, 2012 at 5:49 PM, Paul Ramsey pram...@opengeo.org wrote: Your quotes are misplaced, try os.system('start C:\Program Files (x86)\PostgreSQL\9.1\bin\pgsql2shp.exe -f D:\testShapefile.shp -h localhost -u postgres -p 5432 test_db SELECT * FROM myschema.testquery') On Mon, Feb 20, 2012 at 2:24 PM, David Quinn daithiqu...@gmail.com wrote: I'm trying to call the pgsql2shp.exe function using python, as I would like to be able to loop through some tables. What I've tried doing is the following: import os os.system('start C:\Program Files (x86)\PostgreSQL\9.1\bin\pgsql2shp.exe -f D:\testShapefile.shp -h localhost -u postgres -p 5432 test_db SELECT * FROM myschema.testquery') When I paste the line: C:\Program Files (x86)\PostgreSQL\9.1\bin\pgsql2shp.exe -f D:\testShapefile.shp -h localhost -u postgres -p 5432 test_db SELECT * FROM myschema.testquery it produces a shapefile without a problem. However, my python script flashes open a CMD terminal, but it disappears before I see what is happening and does not produce any output. I'm using PostGIS 2.0, Windows 7, and Python 2.6.5. If there is an alternative approach to python for this, I will happily try it out. (I hope this question is not too off-topic!) Thanks, David ___ postgis-users mailing list postgis-users@postgis.refractions.net http://postgis.refractions.net/mailman/listinfo/postgis-users ___ postgis-users mailing list postgis-users@postgis.refractions.net http://postgis.refractions.net/mailman/listinfo/postgis-users ___ postgis-users mailing list postgis-users@postgis.refractions.net http://postgis.refractions.net/mailman/listinfo/postgis-users
Re: [postgis-users] Calling pgsql2shp.exe via python
David Just to be sure: You did make one single line without line breaks from the mail? os.system('start C:\Program Files (x86)\PostgreSQL\9.1\bin\pgsql2shp.exe -f D:\testShapefile.shp -h localhost -u postgres -p 5432 test_db SELECT * FROM myschema.testquery') -Stefan 2012/2/20 David Quinn daithiqu...@gmail.com: I did try that and got the following error message: Windows cannot find '-f'. Make sure that you typed the name correctly, and then try again. On Mon, Feb 20, 2012 at 5:49 PM, Paul Ramsey pram...@opengeo.org wrote: Your quotes are misplaced, try os.system('start C:\Program Files (x86)\PostgreSQL\9.1\bin\pgsql2shp.exe -f D:\testShapefile.shp -h localhost -u postgres -p 5432 test_db SELECT * FROM myschema.testquery') On Mon, Feb 20, 2012 at 2:24 PM, David Quinn daithiqu...@gmail.com wrote: I'm trying to call the pgsql2shp.exe function using python, as I would like to be able to loop through some tables. What I've tried doing is the following: import os os.system('start C:\Program Files (x86)\PostgreSQL\9.1\bin\pgsql2shp.exe -f D:\testShapefile.shp -h localhost -u postgres -p 5432 test_db SELECT * FROM myschema.testquery') When I paste the line: C:\Program Files (x86)\PostgreSQL\9.1\bin\pgsql2shp.exe -f D:\testShapefile.shp -h localhost -u postgres -p 5432 test_db SELECT * FROM myschema.testquery it produces a shapefile without a problem. However, my python script flashes open a CMD terminal, but it disappears before I see what is happening and does not produce any output. I'm using PostGIS 2.0, Windows 7, and Python 2.6.5. If there is an alternative approach to python for this, I will happily try it out. (I hope this question is not too off-topic!) Thanks, David ___ postgis-users mailing list postgis-users@postgis.refractions.net http://postgis.refractions.net/mailman/listinfo/postgis-users ___ postgis-users mailing list postgis-users@postgis.refractions.net http://postgis.refractions.net/mailman/listinfo/postgis-users ___ postgis-users mailing list postgis-users@postgis.refractions.net http://postgis.refractions.net/mailman/listinfo/postgis-users ___ postgis-users mailing list postgis-users@postgis.refractions.net http://postgis.refractions.net/mailman/listinfo/postgis-users
Re: [postgis-users] Calling pgsql2shp.exe via python
Stefan Yes - It's just one line in my python file and I double-checked my quotes. -David On Mon, Feb 20, 2012 at 6:04 PM, Stefan Keller sfkel...@gmail.com wrote: David Just to be sure: You did make one single line without line breaks from the mail? os.system('start C:\Program Files (x86)\PostgreSQL\9.1\bin\pgsql2shp.exe -f D:\testShapefile.shp -h localhost -u postgres -p 5432 test_db SELECT * FROM myschema.testquery') -Stefan 2012/2/20 David Quinn daithiqu...@gmail.com: I did try that and got the following error message: Windows cannot find '-f'. Make sure that you typed the name correctly, and then try again. On Mon, Feb 20, 2012 at 5:49 PM, Paul Ramsey pram...@opengeo.org wrote: Your quotes are misplaced, try os.system('start C:\Program Files (x86)\PostgreSQL\9.1\bin\pgsql2shp.exe -f D:\testShapefile.shp -h localhost -u postgres -p 5432 test_db SELECT * FROM myschema.testquery') On Mon, Feb 20, 2012 at 2:24 PM, David Quinn daithiqu...@gmail.com wrote: I'm trying to call the pgsql2shp.exe function using python, as I would like to be able to loop through some tables. What I've tried doing is the following: import os os.system('start C:\Program Files (x86)\PostgreSQL\9.1\bin\pgsql2shp.exe -f D:\testShapefile.shp -h localhost -u postgres -p 5432 test_db SELECT * FROM myschema.testquery') When I paste the line: C:\Program Files (x86)\PostgreSQL\9.1\bin\pgsql2shp.exe -f D:\testShapefile.shp -h localhost -u postgres -p 5432 test_db SELECT * FROM myschema.testquery it produces a shapefile without a problem. However, my python script flashes open a CMD terminal, but it disappears before I see what is happening and does not produce any output. I'm using PostGIS 2.0, Windows 7, and Python 2.6.5. If there is an alternative approach to python for this, I will happily try it out. (I hope this question is not too off-topic!) Thanks, David ___ postgis-users mailing list postgis-users@postgis.refractions.net http://postgis.refractions.net/mailman/listinfo/postgis-users ___ postgis-users mailing list postgis-users@postgis.refractions.net http://postgis.refractions.net/mailman/listinfo/postgis-users ___ postgis-users mailing list postgis-users@postgis.refractions.net http://postgis.refractions.net/mailman/listinfo/postgis-users ___ postgis-users mailing list postgis-users@postgis.refractions.net http://postgis.refractions.net/mailman/listinfo/postgis-users ___ postgis-users mailing list postgis-users@postgis.refractions.net http://postgis.refractions.net/mailman/listinfo/postgis-users
Re: [postgis-users] Calling pgsql2shp.exe via python
Be careful with the double quotes Dr. Horst Düster Kappasys Alte Bernstrasse 13 CH-4500 Solothurn Tel.: +41 (0) 32 514 00 40 Mobil: +41 (0) 76 408 51 06 eMail: horst.dues...@kappasys.ch skype: horstduester Twitter: moazagotl Web: www.kappasys.ch lat: N 47° 12' 06.408 lon: E 7° 32' 13.740 Am 21.02.2012 00:11, schrieb David Quinn: Stefan Yes - It's just one line in my python file and I double-checked my quotes. -David On Mon, Feb 20, 2012 at 6:04 PM, Stefan Kellersfkel...@gmail.com wrote: David Just to be sure: You did make one single line without line breaks from the mail? os.system('start C:\Program Files (x86)\PostgreSQL\9.1\bin\pgsql2shp.exe -f D:\testShapefile.shp -h localhost -u postgres -p 5432 test_db SELECT * FROM myschema.testquery') -Stefan 2012/2/20 David Quinndaithiqu...@gmail.com: I did try that and got the following error message: Windows cannot find '-f'. Make sure that you typed the name correctly, and then try again. On Mon, Feb 20, 2012 at 5:49 PM, Paul Ramseypram...@opengeo.org wrote: Your quotes are misplaced, try os.system('start C:\Program Files (x86)\PostgreSQL\9.1\bin\pgsql2shp.exe -f D:\testShapefile.shp -h localhost -u postgres -p 5432 test_db SELECT * FROM myschema.testquery') On Mon, Feb 20, 2012 at 2:24 PM, David Quinndaithiqu...@gmail.com wrote: I'm trying to call the pgsql2shp.exe function using python, as I would like to be able to loop through some tables. What I've tried doing is the following: import os os.system('start C:\Program Files (x86)\PostgreSQL\9.1\bin\pgsql2shp.exe -f D:\testShapefile.shp -h localhost -u postgres -p 5432 test_db SELECT * FROM myschema.testquery') When I paste the line: C:\Program Files (x86)\PostgreSQL\9.1\bin\pgsql2shp.exe -f D:\testShapefile.shp -h localhost -u postgres -p 5432 test_db SELECT * FROM myschema.testquery it produces a shapefile without a problem. However, my python script flashes open a CMD terminal, but it disappears before I see what is happening and does not produce any output. I'm using PostGIS 2.0, Windows 7, and Python 2.6.5. If there is an alternative approach to python for this, I will happily try it out. (I hope this question is not too off-topic!) Thanks, David ___ postgis-users mailing list postgis-users@postgis.refractions.net http://postgis.refractions.net/mailman/listinfo/postgis-users ___ postgis-users mailing list postgis-users@postgis.refractions.net http://postgis.refractions.net/mailman/listinfo/postgis-users ___ postgis-users mailing list postgis-users@postgis.refractions.net http://postgis.refractions.net/mailman/listinfo/postgis-users ___ postgis-users mailing list postgis-users@postgis.refractions.net http://postgis.refractions.net/mailman/listinfo/postgis-users ___ postgis-users mailing list postgis-users@postgis.refractions.net http://postgis.refractions.net/mailman/listinfo/postgis-users ___ postgis-users mailing list postgis-users@postgis.refractions.net http://postgis.refractions.net/mailman/listinfo/postgis-users
Re: [postgis-users] Calling pgsql2shp.exe via python
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']) -David On Mon, Feb 20, 2012 at 6:24 PM, Stefan Keller sfkel...@gmail.com wrote: Yes; it's most probably a quoting problem: See e.g. http://stackoverflow.com/questions/204017/how-do-i-execute-a-program-from-python-os-system-fails-due-to-spaces-in-path -Stefan 2012/2/21 Horst Düster horst.dues...@kappasys.ch: Be careful with the double quotes Dr. Horst Düster Kappasys Alte Bernstrasse 13 CH-4500 Solothurn Tel.: +41 (0) 32 514 00 40 Mobil: +41 (0) 76 408 51 06 eMail: horst.dues...@kappasys.ch skype: horstduester Twitter: moazagotl Web: www.kappasys.ch lat: N 47° 12' 06.408 lon: E 7° 32' 13.740 Am 21.02.2012 00:11, schrieb David Quinn: Stefan Yes - It's just one line in my python file and I double-checked my quotes. -David On Mon, Feb 20, 2012 at 6:04 PM, Stefan Kellersfkel...@gmail.com wrote: David Just to be sure: You did make one single line without line breaks from the mail? os.system('start C:\Program Files (x86)\PostgreSQL\9.1\bin\pgsql2shp.exe -f D:\testShapefile.shp -h localhost -u postgres -p 5432 test_db SELECT * FROM myschema.testquery') -Stefan 2012/2/20 David Quinndaithiqu...@gmail.com: I did try that and got the following error message: Windows cannot find '-f'. Make sure that you typed the name correctly, and then try again. On Mon, Feb 20, 2012 at 5:49 PM, Paul Ramseypram...@opengeo.org wrote: Your quotes are misplaced, try os.system('start C:\Program Files (x86)\PostgreSQL\9.1\bin\pgsql2shp.exe -f D:\testShapefile.shp -h localhost -u postgres -p 5432 test_db SELECT * FROM myschema.testquery') On Mon, Feb 20, 2012 at 2:24 PM, David Quinndaithiqu...@gmail.com wrote: I'm trying to call the pgsql2shp.exe function using python, as I would like to be able to loop through some tables. What I've tried doing is the following: import os os.system('start C:\Program Files (x86)\PostgreSQL\9.1\bin\pgsql2shp.exe -f D:\testShapefile.shp -h localhost -u postgres -p 5432 test_db SELECT * FROM myschema.testquery') When I paste the line: C:\Program Files (x86)\PostgreSQL\9.1\bin\pgsql2shp.exe -f D:\testShapefile.shp -h localhost -u postgres -p 5432 test_db SELECT * FROM myschema.testquery it produces a shapefile without a problem. However, my python script flashes open a CMD terminal, but it disappears before I see what is happening and does not produce any output. I'm using PostGIS 2.0, Windows 7, and Python 2.6.5. If there is an alternative approach to python for this, I will happily try it out. (I hope this question is not too off-topic!) Thanks, David ___ postgis-users mailing list postgis-users@postgis.refractions.net http://postgis.refractions.net/mailman/listinfo/postgis-users ___ postgis-users mailing list postgis-users@postgis.refractions.net http://postgis.refractions.net/mailman/listinfo/postgis-users ___ postgis-users mailing list postgis-users@postgis.refractions.net http://postgis.refractions.net/mailman/listinfo/postgis-users ___ postgis-users mailing list postgis-users@postgis.refractions.net http://postgis.refractions.net/mailman/listinfo/postgis-users ___ postgis-users mailing list postgis-users@postgis.refractions.net http://postgis.refractions.net/mailman/listinfo/postgis-users ___ postgis-users mailing list postgis-users@postgis.refractions.net http://postgis.refractions.net/mailman/listinfo/postgis-users ___ postgis-users mailing list postgis-users@postgis.refractions.net http://postgis.refractions.net/mailman/listinfo/postgis-users ___ postgis-users mailing list postgis-users@postgis.refractions.net http://postgis.refractions.net/mailman/listinfo/postgis-users
Re: [postgis-users] Calling pgsql2shp.exe via python
On 21 February 2012 13:39, David Quinn daithiqu...@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 ___ postgis-users mailing list postgis-users@postgis.refractions.net http://postgis.refractions.net/mailman/listinfo/postgis-users