Paramiko stdout.readlines() vs channel.recv()

1.4k Views Asked by At

I'm new to python paramiko. I know there are two ways to execute a command in a remote server invokde_shell and exec_command. In few cases the output is read using stdout.readlines() whereas in other cases using channel.recv with exit_status as loop condition. It is very difficult to understand the difference between both and which one to use for my script. Can anyone please explain ?

1

There are 1 best solutions below

0
On

This is rather broad question, so only briefly:
readlines vs recv – This is nothing Paramiko-specific. You have the same set of functions, when reading local files or local program input. Use whatever fits your needs. If you need to read by bytes (e.g. when processing a binary input), you probably want to use recv (or read). If you want to process a textual input by lines, use readlines (or readline).

You also mix in shell vs. exec into your question, what is a separate stuff, covered here:
What is the difference between exec_command and send with invoke_shell() on Paramiko?


Overall, you better ask a specific question about implementing your specific problem.