Running grep through Python - doesn't work
<p>I have some code like this:</p>

<pre><code>f = open("words.txt", "w")
subprocess.call(["grep", p, "/usr/share/dict/words"], stdout=f)
f.close()
</code></pre>

<p>I want to grep the MacOs dictionary for a certain pattern and write the results to <code>words.txt</code>. For example, if I want to do something like <code>grep '\&lt;a.\&gt;' /usr/share/dict/words</code>, I'd run the above code with <code>p = "'\&lt;a.\&gt;'"</code>. However, the subprocess call doesn't seem to work properly and <code>words.txt</code> remains empty. Any thoughts on why that is? Also, is there a way to apply regex to <code>/usr/share/dict/words</code> without calling a grep-subprocess?</p>

<p>edit:
When I run <code>grep '\&lt;a.\&gt;' /usr/share/dict/words</code> in my terminal, I get words like: aa
ad
ae
ah
ai
ak
al
am
an
ar
as
at
aw
ax
ay as results in the terminal (or a file if I redirect them there). This is what I expect <code>words.txt</code> to have after I run the subprocess call. </p>