[DUG] Shell Execute
Conor Boyd
Conor_Boyd at trimble.com
Mon Feb 13 11:57:36 NZDT 2012
There are a number of reasons why a lot of developers quickly move on to using CreateProcess instead of ShellExecute.
Gives you a lot more control over the environment in which to run the app you’re trying to invoke.
Can control the environment variables, get handles to the stdout and stderr streams, etc.
Cheers,
Conor
From: delphi-bounces at listserver.123.net.nz [mailto:delphi-bounces at listserver.123.net.nz] On Behalf Of John Bird
I recall there are undocumented limits on the length of line that can be executed as well from cmd and batch files, as well features such as redirect ( > and >> and | ). These may or may not work at cmd prompt level and may not work the same from a batch file, and similar limitations likely apply to Shellexecute. I was wondering if the length of your command might be hitting such a limit.
The advantage of a batch file is you can test it from a cmd prompt, if it works there then if should work from shellexecute.
I would also be inclined to put the SQL into a separate file if there was an option to do that just for tidiness, or at least put the SQL and the encoding options into separate strings, so that each can be made standard.
From: Conor Boyd <mailto:Conor_Boyd at trimble.com>
You can only ShellExecute one command at a time. You’ll have to have two separate calls to ShellExecute for your two invocations of ogr2ogr.
Only other way I can think might work would be to write a temporary batch file with both ogr2ogr invocations in it, and ShellExecute that, but I think two separate calls to ShellExecute would be clearer.
From: delphi-bounces at listserver.123.net.nz [mailto:delphi-bounces at listserver.123.net.nz] On Behalf Of Bob Pawley
Thanks, I missed that. However I still get only the second table blocks. The first table entities is missed.
From: Conor Boyd <mailto:Conor_Boyd at trimble.com>
Unless I’m reading it wrong, you’re missing a backslash in the path that you’re constructing to the ogr2ogr binary.
ProgramName :=
'"'+s+'\Quantum GIS Wroclaw\bin'+
'ogr2ogr"
I think there should be a slash after the “bin”?
From: delphi-bounces at listserver.123.net.nz [mailto:delphi-bounces at listserver.123.net.nz] On Behalf Of Bob Pawley
I’m having a further problem with shell execute. There seems to be a dearth of information on the web other than a simple “open” procedure.
The following two part code performs well when I copy and paste it into command prompt.
However when I use it in shell execute there is a problem getting both parts to run together.
In shell execute each part of the code does its thing when the other part is commented out.
I have tried joining the two parts with the ogr2ogr command &&, and as it appears below. I have also removed the second path to ogr2ogr with no joy.
I either get “unable to run” or the second part of the code is recognized with the first part being ignored.
The following is my command prompt code – which works as shown
set PGCLIENTENCODING=LATIN1&&set DXF_ENCODING=LATIN1&&set DXF_INLINE_BLOCKS=FALSE&&set DXF_MERGE_BLOCK_GEOMETRIES=FALSE&&ogr2ogr -f "PostgreSQL" PG:"host=localhost user=postgres dbname=*** password=*****" Water2000.dxf -lco DIM=2 -nlt GEOMETRY -sql "select layer, linetype, subclasses, ogr_style, blockname, blockangle, blockscale, text from entities" -append -update -skipfailures
set PGCLIENTENCODING=LATIN1&&set DXF_ENCODING=LATIN1&&set DXF_INLINE_BLOCKS=FALSE&&set DXF_MERGE_BLOCK_GEOMETRIES=FALSE&&ogr2ogr -f "PostgreSQL" PG:"host=localhost user=postgres dbname=*** password=****" Water2000.dxf -lco DIM=2 -nlt GEOMETRY -append -update -skipfailures -sql "select layer, linetype, subclasses, ogr_style, blockname, text from blocks"
Here is the shell execute code which is giving me a challenge -
ProgramName :=
'"'+s+'\Quantum GIS Wroclaw\bin'+
'ogr2ogr" "-f" '+
'"PostgreSQL";'+
' PG:"host='+DBHost+' user=postgres dbname='+DBName+' password='+Pass+'" "'+ DXFfile +'" '+
' --config DXF_INLINE_BLOCKS FALSE --config DXF_MERGE_BLOCK_GEOMETRIES FALSE --config DXF_ENCODING=UTF8 '+
' -lco DIM=2 -nlt GEOMETRY -overwrite -skipfailures'+
' -sql "select layer, linetype, subclasses, ogr_style, blockname, blockangle, blockscale, text from entities"'+
'"'+s+'\Quantum GIS Wroclaw\bin'+
'ogr2ogr""-f"'+
' "PostgreSQL";'+
'PG:"host='+DBHost+' user=postgres dbname='+DBName+' password='+Pass+'" "'+ DXFfile +'" '+
' --config DXF_INLINE_BLOCKS FALSE --config DXF_MERGE_BLOCK_GEOMETRIES FALSE --config DXF_ENCODING=UTF8 '+
' -lco DIM=2 -nlt GEOMETRY -overwrite -skipfailures'+
' -sql "select layer, linetype, subclasses, ogr_style, blockname, text from blocks"';
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://listserver.123.net.nz/pipermail/delphi/attachments/20120213/41d0d1ef/attachment-0001.html
More information about the Delphi
mailing list