Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 866
Ramana Reddy Avatar asked Sep 13 '25 12:09

Ramana Reddy


1 Answers

With stdin.write

stdin, stdout, stderr = ssh.exec_command('./sum')
stdin.write('8 9\n')
stdin.flush()
like image 130
jijinp Avatar answered Sep 16 '25 03:09

jijinp