[DUG] Command Line from Delphi
Bob Pawley
rjpawley at shaw.ca
Thu Jun 9 08:53:08 NZST 2011
Hi
I want to open and execute a command line application from a Delphi interface. (FWTools ogr2ogr to be specific).
When I cd the command prompt to FWTools bin and use the following argument it converts a dxf file to a PostgreSQL table perfectly.
ogr2ogr -f "PostgreSQL" PG:"host=localhost user=postgres dbname=E5R password=Password" device.dxf -nln Device';
However when I use Delphi code that I found on the internet, the ogr2ogr opens with an error .http://www.delphicorner.f9.co.uk/articles/wapi4.htm
Following is the code I am using.
I have attempted various alternates such as spacing and white space within the path and argument string, with no success.
I could very well be misinterpreting the instructions.
Any help would be appreciated.
procedure TForm1.Button5Click(Sender: TObject);
var
StartInfo : TStartupInfo;
ProcInfo : TProcessInformation;
CreateOK : Boolean;
Wait : Boolean;
ProgramName : String;
begin
ProgramName := 'C:\Program Files (x86)\FWTools2.4.7\bin\ogr2ogr -f "PostgreSQL" PG:"host=localhostuser=postgres dbname=E5R password=Password" device.dxf -nln Device';
{ fill with known state }
FillChar(StartInfo,SizeOf(TStartupInfo),#0);
FillChar(ProcInfo,SizeOf(TProcessInformation),#0);
StartInfo.cb := SizeOf(TStartupInfo);
CreateOK := CreateProcess(nil, PChar(ProgramName), nil, nil,False,
CREATE_NEW_PROCESS_GROUP+NORMAL_PRIORITY_CLASS,
nil, nil, StartInfo, ProcInfo);
{ check to see if successful }
if CreateOK then
begin
//may or may not be needed. Usually wait for child processes
if Wait then
WaitForSingleObject(ProcInfo.hProcess, INFINITE);
end
else
begin
ShowMessage('Unable to run '+ProgramName);
end;
CloseHandle(ProcInfo.hProcess);
CloseHandle(ProcInfo.hThread);
end;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://listserver.123.net.nz/pipermail/delphi/attachments/20110608/95eaf57c/attachment.html
More information about the Delphi
mailing list