To debug the command, it can be helpful to echo
it instead of running it, to see if any special characters are throwing things off. From inside a bat file, do:
echo ogr2ogr -sql "SELECT * FROM 'D:\Testi2\own.SHP'.own WHERE Owner like 'Harr%'" D:\Testi2\own.shp D:\Testi2\All.SHP
Which will print:
ogr2ogr -sql "SELECT * FROM 'D:\Testi2\own.SHP'.own WHERE Owner like 'Harr\Testi2\own.shp D:\Testi2\All.SHP
Notice the end of the command is getting screwed up starting at the "%" symbol. Turns out that from within a batch file, you have to escape it by doubling it (but not so on the command line!). So the command becomes:
ogr2ogr -sql "SELECT * FROM 'D:\Testi2\own.SHP'.own WHERE Owner like 'Harr%%'" D:\Testi2\own.shp D:\Testi2\All.SHP
And echo
ing it looks okay now.
And a note about setting up batch files that leverage OSGeo utils-- if you look in the OSGeo4W.bat, you'll see this towards the top:
call "%~dp0\bin\o4w_env.bat"
That's what actually sets up the environment. It can simplify things by leaning on that instead:
@echo off
REM set up the environment
call C:\OSGeo4W64\bin\o4w_env.bat
REM anything from here on out will run in that context
ogr2ogr -sql "SELECT * FROM 'D:\Testi2\own.SHP'.own WHERE Owner like 'Harr%%'" D:\Testi2\own.shp D:\Testi2\All.SHP
@echo on