Get Exceptions from popen in python
<p>I executed this code in python: (test.py)</p>

<pre><code>from subprocess import Popen
p = Popen("file.bat").wait()
</code></pre>

<p>Here is file.bat:</p>

<pre><code>@echo off
start c:\python27\python.exe C:\Test\p1.py %*
start c:\python27\python.exe C:\Test\p2.py %*
pause
</code></pre>

<p>Here is p1.py:</p>

<pre><code>This line is error
print "Hello word"
</code></pre>

<p>p2.py is not interesting</p>

<p>I want to know the exception(not only compiling error) in p1.py by running test.py?
How can I do this?</p>

<p>Thanks!</p>

<p>Here's how I got it working:
<code>test.py</code></p>

<pre><code>from subprocess import Popen
p = Popen(["./file.sh"]).wait()
</code></pre>

<p>Make sure to add the <code>[]</code> around file, as well as the <code>./</code>. You can also add arguments, like so:
<code>["./file.sh", "someArg"]</code>
Note that I am not on Windows, but this fixed it on Ubuntu. Please comment if you are still having issues</p>

<p>EDIT:
I think the real solution is: <a href="http://stackoverflow.com/questions/912830/using-subprocess-to-run-python-script-on-windows">Using subprocess to run Python script on Windows</a></p>

<p>This way you can run a python script from python, while still using Popen</p>

python subprocess popen