5

I am trying to run the following shp2pgsql cmd using the OSGeo4W shell:

shp2pgsql -s 4269 -g geom_4269 -I -W "latin1"
"tl_2012_states" staging.tl_2012_states | 
psql -h localhost -p 5432 -d dvdtwo -U postgres

but I am getting the following error:

'shp2pgsql' is not recognized as an internal or external command, operable program or batch file

I have tried updating the environment variable path to include the PostgreSQL\9.5\bin, but that hasn't worked.

What should I try next, or what do you think my problem is?

I am using, PosgreSQL 9.5, QGIS 2.18.5, PostGIS 2.0

3
  • 2
    If you set the environment in a right way you should not get that message. For example you can open the OSGeo4W shell and run set path=%path%;C:\path_to\PostgreSQL\9.5\bin and if the added path is correct then shp2pgsql just must be found.
    – user30184
    May 4, 2017 at 14:33
  • @user30184 probably not a good idea, see my answer. MS Windows is a special snowflake. May 4, 2017 at 17:35
  • If you run that command in the OSGeo4W shell window it extends the path only in that window. System path is not touched at all.
    – user30184
    May 4, 2017 at 18:36

3 Answers 3

6

is not recognized as an internal or external command, operable program or batch file

OSGeo4W specifically has closed the ticket to add this to the system path. The DLLS may conflict with other system DLLs and cause problems.

You need to statically point to the absolute location of shp2pgsql, in the case of OSGeo4W and with your example, I believe it's

C:\OSGeo4W\bin\shp2pgsql -s 4269 -g geom_4269 -I -W "latin1" "tl_2012_states" staging.tl_2012_states | psql -h localhost -p 5432 -d dvdtwo -U postgres

I got the path from the docs on the directory structure. I have no idea if the docs are correct though.

0
2

Looking at the OSGEO4W package list, I don't see anything related to Postgis (although psql gets installed). So you can not blame OSGEO4W for the missing path entry.

If the Postgis installation does not add the folder to the path, you simply have to expand the command line with the full path to the exe.

It should be C:\Program Files\PostgreSQL\9.5\bin\shp2sql.exe (or wherever you find it in your installation).

0

This worked for me - assuming my install location for osgeo4w is C:\OSGeo4W:

  1. Go to environment variables and edit the Path variable (User variable section if you want it applicable only for your user, System variable for all users)
  2. Click new and add the following path C:\OSGeo4W\bin
  3. If you already have a command prompt / powershell open, don't forget to refresh the environment variables with a refreshenv command
  4. gdalinfo and other commands found in the bin folder should now work!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.