Thanks for the link, Stefan. After testing out a few approaches this worked:<br><br>import subprocess<br>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'])<br>
<br>-David<br><br><div class="gmail_quote">On Mon, Feb 20, 2012 at 6:24 PM, Stefan Keller <span dir="ltr"><<a href="mailto:sfkeller@gmail.com">sfkeller@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Yes; it's most probably a quoting problem: See e.g.<br>
<a href="http://stackoverflow.com/questions/204017/how-do-i-execute-a-program-from-python-os-system-fails-due-to-spaces-in-path" target="_blank">http://stackoverflow.com/questions/204017/how-do-i-execute-a-program-from-python-os-system-fails-due-to-spaces-in-path</a><br>

<br>
-Stefan<br>
<br>
2012/2/21 Horst Düster <<a href="mailto:horst.duester@kappasys.ch">horst.duester@kappasys.ch</a>>:<br>
<div class="HOEnZb"><div class="h5">> Be careful with the double quotes<br>
><br>
> Dr. Horst Düster<br>
> Kappasys<br>
> Alte Bernstrasse 13<br>
> CH-4500 Solothurn<br>
><br>
> Tel.: <a href="tel:%2B41%20%280%29%2032%20514%2000%2040" value="+41325140040">+41 (0) 32 514 00 40</a><br>
> Mobil: <a href="tel:%2B41%20%280%29%2076%20408%2051%2006" value="+41764085106">+41 (0) 76 408 51 06</a><br>
> eMail: <a href="mailto:horst.duester@kappasys.ch">horst.duester@kappasys.ch</a><br>
> skype: horstduester<br>
> Twitter: moazagotl<br>
> Web: <a href="http://www.kappasys.ch" target="_blank">www.kappasys.ch</a><br>
><br>
> lat: N 47° 12' 06.408" lon: E 7° 32' 13.740"<br>
><br>
> Am <a href="tel:21.02.2012%2000" value="+12102201200">21.02.2012 00</a>:11, schrieb David Quinn:<br>
><br>
>> Stefan<br>
>> Yes - It's just one line in my python file and I double-checked my quotes.<br>
>> -David<br>
>><br>
>> On Mon, Feb 20, 2012 at 6:04 PM, Stefan Keller<<a href="mailto:sfkeller@gmail.com">sfkeller@gmail.com</a>>  wrote:<br>
>><br>
>>> David<br>
>>><br>
>>> Just to be sure: You did make one single line without line breaks from<br>
>>> the<br>
>>> mail?<br>
>>><br>
>>> os.system('start "C:\Program Files<br>
>>> (x86)\PostgreSQL\9.1\bin\pgsql2shp.exe" -f D:\testShapefile.shp -h<br>
>>> localhost -u postgres -p 5432 test_db "SELECT * FROM<br>
>>> myschema.testquery"')<br>
>>><br>
>>> -Stefan<br>
>>><br>
>>> 2012/2/20 David Quinn<<a href="mailto:daithiquinn@gmail.com">daithiquinn@gmail.com</a>>:<br>
>>>><br>
>>>> I did try that and got the following error message:<br>
>>>><br>
>>>> "Windows cannot find '-f'. Make sure that you typed the name correctly,<br>
>>><br>
>>> and<br>
>>>><br>
>>>> then try again."<br>
>>>><br>
>>>><br>
>>>> On Mon, Feb 20, 2012 at 5:49 PM, Paul Ramsey<<a href="mailto:pramsey@opengeo.org">pramsey@opengeo.org</a>><br>
>>><br>
>>> wrote:<br>
>>>>><br>
>>>>><br>
>>>>> Your quotes are misplaced, try<br>
>>>>><br>
>>>>> os.system('start "C:\Program Files<br>
>>><br>
>>> (x86)\PostgreSQL\9.1\bin\pgsql2shp.exe"<br>
>>>>><br>
>>>>> -f<br>
>>>>> D:\testShapefile.shp -h localhost -u postgres -p 5432 test_db "SELECT *<br>
>>>>> FROM<br>
>>>>> myschema.testquery"')<br>
>>>>><br>
>>>>><br>
>>>>> On Mon, Feb 20, 2012 at 2:24 PM, David Quinn<<a href="mailto:daithiquinn@gmail.com">daithiquinn@gmail.com</a>><br>
>>>>> wrote:<br>
>>>>>><br>
>>>>>> I'm trying to call the pgsql2shp.exe function using python, as I would<br>
>>>>>> like<br>
>>>>>> to be able to loop through some tables. What I've tried doing is the<br>
>>>>>> following:<br>
>>>>>><br>
>>>>>> import os<br>
>>>>>> os.system('start "C:\Program Files<br>
>>>>>> (x86)\PostgreSQL\9.1\bin\pgsql2shp.exe -f<br>
>>>>>> D:\testShapefile.shp -h localhost -u postgres -p 5432 test_db "SELECT<br>
>>><br>
>>> *<br>
>>>>>><br>
>>>>>> FROM<br>
>>>>>> myschema.testquery""')<br>
>>>>>><br>
>>>>>> When I paste the line:<br>
>>>>>><br>
>>>>>> C:\Program Files (x86)\PostgreSQL\9.1\bin\pgsql2shp.exe -f<br>
>>>>>> D:\testShapefile.shp -h localhost -u postgres -p 5432 test_db "SELECT<br>
>>><br>
>>> *<br>
>>>>>><br>
>>>>>> FROM<br>
>>>>>> myschema.testquery"<br>
>>>>>><br>
>>>>>> it produces a shapefile without a problem. However, my python script<br>
>>>>>> flashes<br>
>>>>>> open a CMD terminal, but it disappears before I see what is happening<br>
>>>>>> and<br>
>>>>>> does not produce any output. I'm using PostGIS 2.0, Windows 7, and<br>
>>>>>> Python<br>
>>>>>> 2.6.5.<br>
>>>>>> If there is an alternative approach to python for this, I will happily<br>
>>>>>> try<br>
>>>>>> it out.<br>
>>>>>><br>
>>>>>> (I hope this question is not too off-topic!)<br>
>>>>>><br>
>>>>>> Thanks,<br>
>>>>>> David<br>
>>>>>><br>
>>>>>><br>
>>>>>><br>
>>>>>><br>
>>>>>> _______________________________________________<br>
>>>>>> postgis-users mailing list<br>
>>>>>> <a href="mailto:postgis-users@postgis.refractions.net">postgis-users@postgis.refractions.net</a><br>
>>>>>> <a href="http://postgis.refractions.net/mailman/listinfo/postgis-users" target="_blank">http://postgis.refractions.net/mailman/listinfo/postgis-users</a><br>
>>>>>><br>
>>>>> _______________________________________________<br>
>>>>> postgis-users mailing list<br>
>>>>> <a href="mailto:postgis-users@postgis.refractions.net">postgis-users@postgis.refractions.net</a><br>
>>>>> <a href="http://postgis.refractions.net/mailman/listinfo/postgis-users" target="_blank">http://postgis.refractions.net/mailman/listinfo/postgis-users</a><br>
>>>><br>
>>>><br>
>>>><br>
>>>><br>
>>>> _______________________________________________<br>
>>>> postgis-users mailing list<br>
>>>> <a href="mailto:postgis-users@postgis.refractions.net">postgis-users@postgis.refractions.net</a><br>
>>>> <a href="http://postgis.refractions.net/mailman/listinfo/postgis-users" target="_blank">http://postgis.refractions.net/mailman/listinfo/postgis-users</a><br>
>>>><br>
>>> _______________________________________________<br>
>>> postgis-users mailing list<br>
>>> <a href="mailto:postgis-users@postgis.refractions.net">postgis-users@postgis.refractions.net</a><br>
>>> <a href="http://postgis.refractions.net/mailman/listinfo/postgis-users" target="_blank">http://postgis.refractions.net/mailman/listinfo/postgis-users</a><br>
>>><br>
>><br>
>><br>
>><br>
>> _______________________________________________<br>
>> postgis-users mailing list<br>
>> <a href="mailto:postgis-users@postgis.refractions.net">postgis-users@postgis.refractions.net</a><br>
>> <a href="http://postgis.refractions.net/mailman/listinfo/postgis-users" target="_blank">http://postgis.refractions.net/mailman/listinfo/postgis-users</a><br>
><br>
> _______________________________________________<br>
> postgis-users mailing list<br>
> <a href="mailto:postgis-users@postgis.refractions.net">postgis-users@postgis.refractions.net</a><br>
> <a href="http://postgis.refractions.net/mailman/listinfo/postgis-users" target="_blank">http://postgis.refractions.net/mailman/listinfo/postgis-users</a><br>
_______________________________________________<br>
postgis-users mailing list<br>
<a href="mailto:postgis-users@postgis.refractions.net">postgis-users@postgis.refractions.net</a><br>
<a href="http://postgis.refractions.net/mailman/listinfo/postgis-users" target="_blank">http://postgis.refractions.net/mailman/listinfo/postgis-users</a><br>
</div></div></blockquote></div><br>