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