title: grep command called from python
body: <p>Platform: Windows</p>
  
  <p>Grep: <a href="http://gnuwin32.sourceforge.net/packages/grep.htm" rel="nofollow">http://gnuwin32.sourceforge.net/packages/grep.htm</a></p>
  
  <p>Python: 2.7.2</p>
  
  <p>Windows command prompt used to execute the commands. </p>
  
  <p>I am searching for the for the following pattern <code>"2345$"</code> in a file.
  Contents of the file are as follows:</p>
  
  <pre><code>abcd    2345
  
  2345
  
  abcd    2345$
  </code></pre>
  
  <p><code>grep "2345$" file.txt</code></p>
  
  <p>grep returns 2 lines (first and second) successfully. </p>
  
  <p>When I try to run the above command through python I don't see any output. 
  Python code snippet is as follows:</p>
  
  <pre><code>temp = open('file.txt', "r+")
  grep_cmd = []
  grep_cmd.extend([grep, '"2345$"' ,temp.name])
  print grep_cmd
  p = subprocess.Popen(grep_cmd, 
          stdout=subprocess.PIPE,
          stderr=subprocess.PIPE)
  stdoutdata = p.communicate()[0]
  print stdoutdata
  </code></pre>
  
  <p>If I have </p>
  
  <pre><code>grep_cmd.extend([grep, '2345$' ,temp.name])
  </code></pre>
  
  <p>in my python script, I get the correct answer. </p>
  
  <p>The questions is why the grep command with <code>"</code> </p>
  
  <pre><code>grep_cmd.extend([grep, '"2345$"' ,temp.name])
  </code></pre>
  
  <p>executed from python fails. Isn't python supposed to execute 
  the command as it is. </p>
  
  <p>Thanks
  Gudge.</p>