First, I think you should use subprocess.Popen (it's recommended by PEP-324) instead of os.popen. For example: <br /><br />p = subprocess.Popen(["top"], stdout = PIPE)<br />p.stdout.readlines()<br /><br />And to write to stdin (in your case "q") you can use p.stdin.write("q"), or terminate the process with p.terminate(), or just specify the -n option (the number of iterations) to the value you desire. It's done in that way: subprocess.Popen(["top","-n 1"], stdout=PIPE)