title: Invoking perl script with variable input and file output as arguments from python
body: <p>I have a perl script that can be executed from the console as follows:</p>
  
  <pre><code>perl perlscript.pl -i input.txt -o output.txt --append
  </code></pre>
  
  <p>I want to execute this script from my python code. I figured out that <code>subprocess.Popen</code> can be used to connect to perl and I can pass my arguments with it. But, I also want to pass a variable (made by splitting up a text file) in place of input.txt. 
  I have tried the following but it doesn't seem to work and gives an obvious TypeError in line 8:</p>
  
  <pre><code>import re, shlex, subprocess, StringIO
  f=open('fulltext.txt','rb')
  text= f.read()
  l = re.split('\n\n',str(text))
  intxt = StringIO.StringIO()
  for i in range(len(l)):
      intxt.write(l[i])
      command_line='perl cnv_ltrfinder2gff.pl -i '+intxt+' -o output.gff --append'
      args=shlex.split(command_line)
      p = subprocess.Popen(args)
  </code></pre>
  
  <p>Is there any other work around for this?</p>
  
  <p>EDIT: Here is a sample of the file fulltext.txt. Entries are separated by a line. </p>
  
  <pre><code>Predict protein Domains 0.021 second
  &gt;Sequence: seq1 Len:13143 [1] seq1 Len:13143 Location : 9 - 13124 Len: 13116 Strand:+ Score    : 6 [LTR region similarity:0.959] Status   : 11110110000 5'-LTR   : 9 - 501 Len: 493 3'-LTR   : 12633 - 13124 Len: 492 5'-TG    : TG , TG 3'-CA    : CA , CA TSR      : NOT FOUND Sharpness: 1,1 Strand + : PBS   : [14/20] 524 - 543 (LysTTT) PPT   : [12/15] 12553 - 12567
  
  Predict protein Domains 0.019 second
  &gt;Sequence: seq5 Len:11539 [1] seq5 Len:11539 Location : 7 - 11535 Len: 11529 Strand:+ Score    : 6 [LTR region similarity:0.984] Status   : 11110110000 5'-LTR   : 7 - 506 Len: 500 3'-LTR   : 11036 - 11535 Len: 500 5'-TG    : TG , TG 3'-CA    : CA , CA TSR      : NOT FOUND Sharpness: 1,1 Strand + : PBS   : [15/22] 515 - 536 (LysTTT) PPT   : [11/15] 11020 - 11034
  </code></pre>
  
  <p>I want to separate them and pass each entry block to the perl script. All the files are in the same directory.</p>