title: How to correctly escape special characters in python subprocess?
body: <p>Im trying to run this bash command using python subprocess </p>
  
  <pre><code>find /Users/johndoe/sandbox -iname "*.py" | awk -F'/' '{ print $NF}'
  </code></pre>
  
  <p>output:-</p>
  
  <pre><code>helld.xl.py
  parse_maillog.py
  replace_pattern.py
  split_text_match.py
  ssh_bad_login.py
  </code></pre>
  
  <p>Here is what i have done in python2.7 way, but it gives the output where awk command filter is not working</p>
  
  <pre><code>&gt;&gt;&gt; p1=subprocess.Popen(["find","/Users/johndoe/sandbox","-iname","*.py"],stdout=subprocess.PIPE)
  
  &gt;&gt;&gt; p2=subprocess.Popen(['awk','-F"/"','" {print $NF} "'],stdin=p1.stdout,stdout=subprocess.PIPE)
  
  &gt;&gt;&gt;p2.communicate()
  ('/Users/johndoe/sandbox/argparse.py\n/Users/johndoe/sandbox/custom_logic_substitute.py\n/Users/johndoe/sandbox/finditer_html_parse.py\n/Users/johndoe/sandbox/finditer_simple.py\n/Users/johndoe/sandbox/group_regex.py\n/Users/johndoe/sandbox/helo.py\n/Users/johndoe/sandbox/newdir/helld.xl.py\n/Users/johndoe/sandbox/parse_maillog.py\n/Users/johndoe/sandbox/replace_pattern.py\n/Users/johndoe/sandbox/split_text_match.py\n/Users/johndoe/sandbox/ssh_bad_login.py\n', None)
  </code></pre>
  
  <p>I could also get output by using p1 alone here like below,but i cant get the awk working here</p>
  
  <pre><code>list1=[]
  result=p1.communicate()[0].split("\n")
  for item in res:
      a=item.rstrip('/').split('/')
      list1.append(a[-1])
  print list1
  </code></pre>