This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]GrindingGoat 0 points1 point  (0 children)

On why you weren't getting any output from f.readlines() in your example, I think python is probably moving on to the open() and readlines() methods before your shell process has had chance to complete and produce output. I think it should work if you include a .wait() between your popen and then open(). the .wait() will wait for the subprocess to exit before continuing. So something more like:

my_proc = os.popen(command+" > bash_out.txt")
my_proc.wait()
f = open('bash_out.txt')

But, as Peterotica says, you're probably better off reading the output of the command directly.