redirecting the output of shell script executing through python
<p>Hi I am trying to execute shell script from python using following command.</p>

<pre><code>os.system("sh myscript.sh")
</code></pre>

<p>in my shell script I have written some SOP's, now how do I get the SOP's in my Python so that I can log them into some file?</p>

<p>I know using <code>subprocess.Popen</code> I can do it, for some reason I can not use it.</p>

<pre><code>p=subprocess.Popen(
        'DMEARAntRunner \"'+mount_path+'\"',
         shell=True,
         stdout=subprocess.PIPE,
         stderr=subprocess.STDOUT
)
while 1:
    line=p.stdout.readline()[:-1]
    if not line:
        break
    write_to_log('INFO',line)
    p.communicate()
</code></pre>
