<div>Besides, If I print the query, I have the next output:</div>
<div><font size="2">
<p align="left">C:/Archivos de programa/FWTools2.4.7/bin/ogr2ogr U3B-BARDA</p>
<p align="left">.shp -where &quot;LAYER=&#39;U3B-BARDA</p>
<p align="left">&#39;&quot; tapalpa_05_plani_line.shp</p>
<p align="left">C:/Archivos de programa/FWTools2.4.7/bin/ogr2ogr N2H-TEMP</p>
<p align="left">.shp -where &quot;LAYER=&#39;N2H-TEMP</p>
<p align="left">&#39;&quot; tapalpa_05_plani_line.shp</p>
<p align="left">C:/Archivos de programa/FWTools2.4.7/bin/ogr2ogr U3C-CERCA</p>
<p align="left">.shp -where &quot;LAYER=&#39;U3C-CERCA</p>
<p align="left">&#39;&quot; tapalpa_05_plani_line.shp..........</p></font>I thought it was a console print issue, but when I run the module from Eclipse, it shows the same enter space, so I think it maybe that the line is not together as it is a statement!!<br>
</div>
<div class="gmail_quote">2010/10/8 Susana Iraiis Delgado Rodriguez <span dir="ltr">&lt;<a href="mailto:susana.delgado_s@utzmg.edu.mx">susana.delgado_s@utzmg.edu.mx</a>&gt;</span><br>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">
<div>Hi Alan:</div>
<div> </div>
<div>The ouput is coming from a cicle and some functions that I vae to do to execute an ogr2ogr command, in this output I ask the user for the name of a file and then make a module to get to the subprocess part:</div>
<div> </div>
<div>import shlex, subprocess, sys</div>
<div>from dbf import *<br>def process():<br>#Read dbfile status 100%</div>
<div>     a = open (&quot;capas.txt&quot;,&quot;w+&quot;)<br>     print &#39;Enter the shapefile name&#39;<br>     b = raw_input()<br>     print &#39;\n&#39;<br>    dbf = Dbf(b+&quot;.dbf&quot;,new=False)<br>   <br>    for rec in dbf:<br>
         for fldName in dbf.fieldNames:<br>             if fldName == &#39;LAYER&#39;:<br>             l=()<br>             l=rec[fldName]<br>             a.write(l)<br>             a.write(&quot;\n&quot;)<br>    a.close()<br>
 <br>##Eliminate duplicate lines from the txt into a new txt, status:100%<br>      a = open (&quot;capas.txt&quot;,&quot;r&quot;)<br>      catalogo = open (&quot;unico.txt&quot;,&quot;w&quot;)<br>      unique = set(a.read().split(&quot;\n&quot;))<br>
      catalogo.write(&quot;&quot;.join([line + &quot;\n&quot; for line in unique]))<br>      catalogo.close()<br>      a.close()<br> <br>##Execute ogr2ogr command, status:75%<br>     for line in open(&quot;unico.txt&quot;, &quot;r&quot;): 
<div class="im"><br>        p = subprocess.Popen([&#39;C:/Archivos de programa/FWTools2.4.7/bin/ogr2ogr&#39;, line+&#39;.shp&#39;, &#39;-where&#39;, &quot;\&quot;LAYER=&#39;&quot;+line+&quot;&#39;\&quot;&quot; , b+&#39;.shp&#39;])<br>
  </div></div>
<div>But when I executed it shows me an error in the layer&#39;s name:</div>
<div><br>&gt;&gt;&gt; ERROR 1: Failed to identify field:LAYER=<br>ERROR 1: Failed to create file .shp file.<br>ERROR 4: Failed to open Shapefile `0<br>.shp&#39;.</div>
<div> </div>
<div>I think the erros showed up because some of the layer&#39;s values are 0 and &#39; &#39;, and obsviously you can&#39;t create a file from nothing on it. But I don`t know how to validate if a layer&#39;s value is equals to 0 or &#39; &#39;, any idea what I&#39;m doing wrong or how to fix it?</div>

<div><br> </div>
<div class="gmail_quote">2010/10/7 Susana Iraiis Delgado Rodriguez <span dir="ltr">&lt;<a href="mailto:susana.delgado_s@utzmg.edu.mx" target="_blank">susana.delgado_s@utzmg.edu.mx</a>&gt;</span> 
<div>
<div></div>
<div class="h5"><br>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">
<div>Hello taserian and Antonio!</div>
<div> </div>
<div>Thank you both for taking the time to answer my question. With taserian&#39;s code it gives me the next output:</div>
<div><font face="courier new,monospace">C... ogr2ogr T21-PUENTESshp -where &quot;LAYER=T21-PUENTES&quot; tapalpa_05_plani_line.shp</font></div>
<div>but the output I need is:</div>
<div><font face="courier new,monospace">C... ogr2ogr T21-PUENTESshp -where &quot;LAYER=&#39; T21-PUENTES&#39; &quot; tapalpa_05_plani_line.shp</font></div>
<div> </div>
<div>I did the Antonio&#39;s suggested corrections, and I got the string I wanted, now the problem is that my subprocess doesn&#39;t work properly, I&#39;ll give a look and see whats wrong with it.</div>
<div> </div>
<div> </div>
<div class="gmail_quote">2010/10/7 taserian <span dir="ltr">&lt;<a href="mailto:taserian@gmail.com" target="_blank">taserian@gmail.com</a>&gt;</span> 
<div>
<div></div>
<div><br>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">
<div class="gmail_quote">
<div>On Thu, Oct 7, 2010 at 12:48 PM, taserian <span dir="ltr">&lt;<a href="mailto:taserian@gmail.com" target="_blank">taserian@gmail.com</a>&gt;</span> wrote:<br>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">I&#39;m adding some line breaks to make your text a little more readable.<br><br>
<div class="gmail_quote">On Thu, Oct 7, 2010 at 9:55 AM, Susana Iraiis Delgado Rodriguez <span dir="ltr">&lt;<a href="mailto:susana.delgado_s@utzmg.edu.mx" target="_blank">susana.delgado_s@utzmg.edu.mx</a>&gt;</span> wrote: 
<div>
<div></div>
<div><br>
<blockquote style="BORDER-LEFT: rgb(204,204,204) 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">
<div>Hello members:</div>
<div> </div>
<div>How can I write a statement to execute the following:</div>
<div></div></blockquote>
<div> </div>
<blockquote style="BORDER-LEFT: rgb(204,204,204) 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">
<div>C:/Archivos de programa/FWTools2.4.7/bin/ogr2ogr R1G-GEODESIA.shp -where &quot;LAYER = &#39;R1G-GEODESIA&#39;&quot; tapalpa_05_plani_point.dbf</div></blockquote>
<div> </div>
<blockquote style="BORDER-LEFT: rgb(204,204,204) 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">
<div>I want my uotput to look like this.</div>
<div>Instead I&#39;m getting this</div></blockquote>
<div> </div>
<blockquote style="BORDER-LEFT: rgb(204,204,204) 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">
<div>C:/Archivos de programa/FWTools2.4.7/bin/ogr2ogr T21-PUENTES.shp -where LAYER=+line tapalpa_05_plani_line.shp</div>
<div></div></blockquote>
<div> </div>
<blockquote style="BORDER-LEFT: rgb(204,204,204) 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">
<div>In miy code line is a string given by the user:</div>
<div> </div>
<div>for line in open(&quot;unico.txt&quot;, &quot;r&quot;).readlines():</div>
<div>     p = subprocess.Popen([&#39;C:/Archivos de programa/FWTools2.4.7/bin/ogr2ogr&#39;, line+&#39;.shp&#39;, &#39;-where&#39;, &quot;LAYER=&#39;line&#39;&quot;, b+&#39;.shp&#39;])</div>
<div> </div>
<div>Any suggestions?</div></blockquote>
<div><br></div></div></div>
<div>Without knowing specifics about what the subprocess.Popen function is expecting as parameters, I can only speculate, but it seems that the following *might* work (for extremely generous values of &quot;*might*&quot;):</div>

<div>
<div><br></div>
<div>
<div>for line in open(&quot;unico.txt&quot;, &quot;r&quot;).readlines():</div>
<div>     p = subprocess.Popen([&#39;C:/Archivos de programa/FWTools2.4.7/bin/ogr2ogr&#39;, line+&#39;.shp&#39;, &#39;-where&#39;, &quot;\&quot;LAYER=&#39;&quot; + line + &quot;&#39;\&quot;&quot;, b+&#39;.shp&#39;])</div>
</div>
<div><br></div></div>
<div>Details about where the changes are:</div>
<div>&quot;\&quot;LAYER=&#39;&quot; + line + &quot;&#39;\&quot;&quot;</div></div></blockquote>
<div><br></div></div>
<div>Begin corrections (corrections start with a *) </div>
<div>
<div><br></div>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">
<div class="gmail_quote">
<div></div>
<div>Quote to begin the literal: &quot;</div>
<div>An escaped quote (1) so that there&#39;s a quote inside the literal: \&quot;</div>
<div>Some of the text that&#39;s meant to be unchanging: LAYER=</div></div></blockquote></div>
<div>*Single Quote (2) to be included in the literal (which doesn&#39;t need to be escaped): &#39;</div>
<div>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">
<div class="gmail_quote">
<div>Close Quote: &quot;</div></div></blockquote>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">
<div class="gmail_quote">
<div>Add the content of the variable &quot;line&quot; from the unico.txt file:  + line +</div></div></blockquote></div>
<div>*Add another literal, composed of the single quote that closes (2) above, then the closing escaped quote to close (1) : &quot;&#39;\&quot;&quot; </div>
<div>
<div> </div>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">
<div class="gmail_quote">
<div><br></div>
<div>See if this works, and let us know how it turns out.</div>
<div><br></div>
<div>Antonio Rodriguez</div></div></blockquote></div></div>
<div><br></div>
<div>End of corrections.</div><br>
<div>Antonio Rodriguez</div></blockquote></div></div></div><br></blockquote></div></div></div><br></blockquote></div><br>