擅长:python、mysql、java
<pre><code>from subprocess import Popen, PIPE
from getpass import getpass
x = Popen('ssh root@host', stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=True)
print x.stdout.readline()
_pass = getpass('Enter your superduper password:')
x.stdin.write(_pass)
print x.stdout.readline()
</code></pre>
<p>一旦连接,您仍然可以通过<code>x.stdin.write(...)</code>输入东西,就好像您在另一台机器上一样,所以是的,应该可以工作吗?</p>
<p>调试(只需启动一个命令提示符,导航到python目录并编写python):</p>
<pre><code>C:\Users>python
Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from getpass import getpass
>>> getpass('test: ')
test:
'This is a test'
>>>
</code></pre>