我试图在机器之间创建一个SCP文件,并且当用户没有设置用于执行无密码登录的私有/公共证书时,我需要失败。不幸的是,使用subprocess.Popen我无法弄清楚如何捕获以下的输出:Python子进程+ scp - 无法读取所有输出
The authenticity of host '***' can't be established.
RSA key fingerprint is ***.
Are you sure you want to continue connecting (yes/no)
它总是显示在控制台上,我不能在我的程序来检测它得到它。
下面是一些示例代码:
proc = subprocess.Popen(['scp', '[email protected]:/location/file.txt', '/someplace/file.txt',
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
proc.wait()
print 'result: %s' % repr(proc.stderr.readline())
我试过很多其他的排列。这个仍然提示我,而不是Python进入是/否。至少当我键入没有,虽然我得到:
result: 'Host key verification failed.\r\n'
你可能要考虑尝试[paramiko](http://www.lag.net/paramiko/)这是一个本地的Python SSH库。你将会对连接有更多的控制权,并且不必处理Popen。 – 2011-06-08 22:43:17
你正在挂stderr吗? – 2011-06-08 22:43:30
@ greg-hewgill在这种情况下,我不能使用第三方库。 – sudoer 2011-06-08 22:50:26