I am reading a .exp file opened in VI on a remote server using python. While Option 2 works for me, it can't read ~1024 bytes at a time. Is my usage of iterator object incorrect in Option 1? Also, I can't figure out why I am unable to read from the stdout buffer more than 512 byte chunks at a time.
Option 1:
#Output: Can't Read File!
target = open("out.txt", 'w')
def readFile():
return (str(stdout.read(512))).splitlines(True)
try:
stdin, stdout, stderr = ssh.exec_command('vi <path\filename.exp>')
for line in iter(readFile,''):
target.write(line)
stdin, stdout, stderr=ssh.exec_command(':q!')
except:
print("Can't Read File!")
Option 2:
#works, but hangs when using stdout.read(1024)
try:
stdin, stdout, stderr = ssh.exec_command('vi <path\filename.exp>')
to_string = (str(stdout.read(512))).splitlines(True)
for line in to_string:
target.write(line)
stdin, stdout, stderr=ssh.exec_command(':q!')
except:
print("Can't Read File!")