如何在 python 中使用 paramiko 将输入发送到命令?

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

有一个命令,基本上是一个 c 程序,当在远程机器上执行时。执行该命令后,它需要一些输入。就像:

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

如何在 ssh.exec_command("./sum") 之后使用 paramiko 执行此操作?如何将输入 8 和 9 发送给它。

stdin.write

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