Having issues reading a remote file while using subprocess

422 Views Asked by At

I do the following and not able to read the file "word_file.txt" line by line..

 f = subprocess.Popen(["../../../script.sh", "cat", "word_file.txt"], stdout=subprocess.PIPE)
            out = f.stdout.readline()
            print "......."
            for i in f.stdout.readline():
                print "I>>>>>>>>>>>", i

the i that gets printed, prints every single character separately.

So, I tried doing..

for i in f.stdout.readline().split('\n'):
            print "I>>>>>>>>>>>", i

Read remote file using python subprocess and ssh? - addresses the same issue but their solution isnt working for me.

But that does not seem the right this to do. I get no output..

1

There are 1 best solutions below

0
On BEST ANSWER

use iter with readline to read each full line:

for i in iter(f.stdout.readline,"")