title: How do I use a subprocess to run a shell program within a python loop?
body: <pre><code>num_of_files = 12
  pair_count = 1
  while pair_count &lt; num_of_files:
      for root, dirs, all_files in os.walk(indir):
          read1 = all_files[pair_count]
          pair_count += 1
          read2 = all_files[pair_count]
          print(read1, read2)
          pair_count += 1
          process = subprocess.Popen
  (cutadapt -a AATGATACGGCGACCACCGAGATCTACACGCCTCCCTCGCGCCATCAG
   -o out1.fastq -p out.2fastq read1 read2, shell=True, stdout=subprocess.PIPE)
  if pair_count &gt; num_of_files:
          break
  </code></pre>
  
  <p>I seem to be having trouble using the cutadapt shell script within my python loop. It gives the following error message when I run it:</p>
  
  <pre><code>process = subprocess.Popen(cutadapt -a AATGATACGGCGACCACCGAGATCTACACGCCTCCCTCGCGCCATCAG 
  -o out1.fastq -p out.2fastq read1 read2, shell=True, stdout=subprocess.PIPE)
  
                        SyntaxError: invalid syntax                                     ^
  </code></pre>
  
  <p>The error indicates the end of the string... I'm not sure what syntax error this could be. </p>
  
  <p>Any help with this would be appreciated</p>