Python : reading output from os.popen4 before writing writing stdin
<p>I have a script which executes some command using os.popen4. Problem is some time command being executed will require user input ("y" or "n"). I am reading stdout/stderr and printing it, but it seems question from command doesn't got printed and it hangs. To make it work, i had to write "n" to stdin blindly. Can some one please guide on how to handle it?</p>

<p>Code not working:</p>

<pre><code>   (f_p_stdin, f_p_stdout_stderr) = os.popen4(cmd_exec,"t")
    cmd_out = f_p_stdout_stderr.readlines()
    print cmd_out
    f_p_stdin.write("n")
    f_p_stdin.close()
    f_p_stdout_stderr.close()
</code></pre>

<p>Working Code:</p>

<pre><code>   (f_p_stdin, f_p_stdout_stderr) = os.popen4(cmd_exec,"t")
    cmd_out = f_p_stdout_stderr.readlines()
    f_p_stdin.write("n")
    f_p_stdin.close()
    print cmd_out
    f_p_stdout_stderr.close()
</code></pre>

<p>NOTE : I am aware that it is depreciated and subprocess module is used, but right now i don't know on how to use it. So i'll appreciate if some one will help me to handle it using os.popen4. I want to capture the question and handle the input from user and execute it.</p>
