title: Formatting a command in python subprocess popen
body: <p>I am trying to format the following awk command</p>
  
  <pre><code>awk -v OFS="\t" '{printf "chr%s\t%s\t%s\n", $1, $2-1, $2}' file1.txt &gt; file2.txt
  </code></pre>
  
  <p>for use in python subprocess popen. However i am having a hard time formatting it. I have tried solutions suggested in similar answers but none of them worked. I have also tried using raw string literals. Also i would not like to use <em>shell=True</em> as this is not recommended</p>
  
  <p>Edit according to comment:
  The command i tried was</p>
  
  <pre><code>awk_command = """awk -v OFS="\t" '{printf "chr%s\t%s\t%s\n", $1, $2-1, $2}' file1.txt &gt; file2.txt"""
  command_execute = Popen(shlex.split(awk_command))
  </code></pre>
  
  <p>However i get the following error upon executing this</p>
  
  <pre><code>KeyError: 'printf "chr%s\t%s\t%s\n", $1, $2-1, $2'
  </code></pre>
  
  <p>googling the error suggests this happens when a value is requested for an undefined key but i do not understand its context here</p>