Python: Auto response to the console output
<p>I am running an os command in python script and the command ask do you want to continue after running for sometime and it does that many times while it runs. I want to see if there is a way in python where it answers yes every time it sees its waiting for user confirmation.</p>

<p>Dint find much help.</p>

<p>If someone can paste some example.</p>

<p>Finally I figured it out.</p>

<pre><code>#!/usr/bin/python
import subprocess
import os

f = open('test', 'r')
for i in f.readlines():
    cmd = '/usr/sbin/nsrmm -d -S ' + i
    cmd1 = cmd.split( )
    print cmd1
    p = subprocess.Popen(cmd1, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
    p.stdin.write('y')
</code></pre>

python