0

I am trying to execute pgsql2shp for a remote postgres db using batch file using the below code

for /f %%i in ('psql -U ihadmin -d ih_gis_production -h <xxxxx> -c "select f_table_name from geometry_columns where f_table_schema='mls_dataset';"') do (
set file_name=D:/Processing/DB_Dump/airdrie/mls_datatset/%%i
set table_name=%%i
pgsql2shp -h <xxxxx> -f %file_name% -u ihadmin -P xxxxx ih_gis_production mls_dataset.%table_name%
)

This will get table names from from the above select query and loop and export those tables to shapefile. When i run this from batch file, i am seeing pgsql2shp help options in command prompt. Any correct way to call pgsql2shp via batch ?

User123
  • 793
  • 4
  • 10
  • 28
  • 1
    I guess that you need [Delayed Expansion](https://ss64.com/nt/delayedexpansion.html) as `pgsql2shp -h -f !file_name! -u ihadmin -P xxxxx ih_gis_production mls_dataset.!table_name!` or omit intermediate variables at all using `pgsql2shp -h -f D:/Processing/DB_Dump/airdrie/mls_datatset/%%i -u ihadmin -P xxxxx ih_gis_production mls_dataset.%%i` – JosefZ May 15 '20 at 14:32
  • No Luck.Didnt work – User123 May 15 '20 at 14:44
  • There is actually no reason to assign interim variables; simply use `%%i` immediately, like `pgsql2shp -h -f "D:\Processing\DB_Dump\airdrie\mls_datatset\%%i" -u ihadmin -P xxxxx ih_gis_production mls_dataset.%%i`. By the way: the Windows path separator is `\ `but not `/`... – aschipfl May 16 '20 at 18:57

0 Answers0