<p>Quote any parameters with spaces in them.</p>
<div class="gmail_quote">On 09/06/2011 6:55 AM, "Bob Pawley" <<a href="mailto:rjpawley@shaw.ca">rjpawley@shaw.ca</a>> wrote:<br type="attribution">> Hi<br>> <br>> I want to open and execute a command line application from a Delphi interface. (FWTools ogr2ogr to be specific).<br>
> <br>> When I cd the command prompt to FWTools bin and use the following argument it converts a dxf file to a PostgreSQL table perfectly.<br>> <br>> ogr2ogr -f "PostgreSQL" PG:"host=localhost user=postgres dbname=E5R password=Password" device.dxf -nln Device';<br>
> <br>> However when I use Delphi code that I found on the internet, the ogr2ogr opens with an error .<a href="http://www.delphicorner.f9.co.uk/articles/wapi4.htm">http://www.delphicorner.f9.co.uk/articles/wapi4.htm</a><br>
> <br>> Following is the code I am using.<br>> <br>> I have attempted various alternates such as spacing and white space within the path and argument string, with no success.<br>> <br>> I could very well be misinterpreting the instructions.<br>
> <br>> Any help would be appreciated.<br>> <br>> procedure TForm1.Button5Click(Sender: TObject);<br>> <br>> var<br>> StartInfo : TStartupInfo;<br>> ProcInfo : TProcessInformation;<br>> CreateOK : Boolean;<br>
> Wait : Boolean;<br>> ProgramName : String;<br>> <br>> begin<br>> ProgramName := 'C:\Program Files (x86)\FWTools2.4.7\bin\ogr2ogr -f "PostgreSQL" PG:"host=localhostuser=postgres dbname=E5R password=Password" device.dxf -nln Device';<br>
> { fill with known state }<br>> FillChar(StartInfo,SizeOf(TStartupInfo),#0);<br>> FillChar(ProcInfo,SizeOf(TProcessInformation),#0);<br>> StartInfo.cb := SizeOf(TStartupInfo);<br>> <br>> CreateOK := CreateProcess(nil, PChar(ProgramName), nil, nil,False,<br>
> CREATE_NEW_PROCESS_GROUP+NORMAL_PRIORITY_CLASS,<br>> nil, nil, StartInfo, ProcInfo);<br>> { check to see if successful }<br>> if CreateOK then<br>> begin<br>> //may or may not be needed. Usually wait for child processes<br>
> if Wait then<br>> WaitForSingleObject(ProcInfo.hProcess, INFINITE);<br>> end<br>> else<br>> begin<br>> ShowMessage('Unable to run '+ProgramName);<br>> end;<br>
> CloseHandle(ProcInfo.hProcess);<br>> CloseHandle(ProcInfo.hThread);<br>> <br>> <br>> end;<br></div>