Passing shell commands with Python os.system() or subprocess.check_call()
<p>I'm trying to call 'sed' from Python and having troubles passing the command line via either subprocess.check_call() or os.system().</p>

<p>I'm on Windows 7, but using the 'sed' from Cygwin (it's in the path).</p>

<p>If I do this from the Cygwin shell, it works fine:</p>

<pre><code>$ sed 's/&amp;amp;nbsp;/\&amp;nbsp;/g' &lt;"C:foobar" &gt;"C:foobar.temp"
</code></pre>

<p>In Python, I've got the full pathname I'm working with in "name".  I tried:</p>

<pre><code>command = r"sed 's/&amp;amp;nbsp;/\&amp;nbsp;/g' " +  "&lt;" '\"' + name + '\" &gt;' '\"' + name + '.temp' + '\"'
subprocess.check_call(command, shell=True)
</code></pre>

<p>All the concatenation is there to make sure I have double quotes around the input and output filenames (in case there are blank spaces in the Windows file path).</p>

<p>I also tried it replacing the last line with:</p>

<pre><code>os.system(command)
</code></pre>

<p>Either way, I get this error:</p>

<pre><code>sed: -e expression #1, char 2: unterminated `s' command
'amp' is not recognized as an internal or external command,
operable program or batch file.
'nbsp' is not recognized as an internal or external command,
operable program or batch file.
</code></pre>

<p>Yet, as I said, it works OK from the console.  What am I doing wrong?                </p>
