Ramana Reddy
Ramana Reddy

Reputation: 399

How to send inputs to a command using paramiko in python?

There is a command, basically a c program, when executed on the remote machine. After executing that command it expects some inputs. Just like:

./sum
Enter two value: 8 9
sum is 17

How do I do this with paramiko after ssh.exec_command("./sum")? How to send the inputs 8 and 9 to it.

Upvotes: 4

Views: 6320

Answers (1)

jijinp
jijinp

Reputation: 2672

With stdin.write

stdin, stdout, stderr = ssh.exec_command('./sum')
stdin.write('8 9\n')
stdin.flush()

Upvotes: 6

Related Questions