Closed pbrezina closed 1 year ago
Calling list(output.stdout) returns the whole output correctly as expected:
list(output.stdout)
conn = pssh.clients.ssh.SSHClient( host='client.test', user='root', password='Secret123', ) output = conn.run_command('echo -e "line1\nline2"') print('start') print(list(output.stdout)) print('finished') start ['line1', 'line2'] finished
However, if I want to return line by line by calling next(generator), then it only gets the first line, the second call raises StopIteration.
next(generator)
StopIteration
conn = pssh.clients.ssh.SSHClient( host='client.test', user='root', password='Secret123', ) output = conn.run_command('echo -e "line1\nline2"') print('start') print(next(output.stdout)) print(next(output.stdout)) print('finished') conn = pssh.clients.ssh.SSHClient( host='client.test', user='root', password='Secret123', ) output = conn.run_command('echo -e "line1\nline2"') print('start') print(next(output.stdout)) > print(next(output.stdout)) E StopIteration
If I read first line and the call list, the result is empty - it does not get the rest.
conn = pssh.clients.ssh.SSHClient( host='client.test', user='root', password='Secret123', ) output = conn.run_command('echo -e "line1\nline2"') print('start') print(next(output.stdout)) print('finished') conn.wait_finished(output) print(list(output.stdout)) start line1 finished []
Reproducers are with libssh client, but it does not work with libssh2 as well.
Nevermind, this was my poor understanding of how generators work.
Calling
list(output.stdout)
returns the whole output correctly as expected:However, if I want to return line by line by calling
next(generator)
, then it only gets the first line, the second call raisesStopIteration
.If I read first line and the call list, the result is empty - it does not get the rest.
Reproducers are with libssh client, but it does not work with libssh2 as well.