[英]diverting the stdin when ssh-ing to another machine from python
I am trying to use SSH as a socks proxy to another machine, then ask the user if he wants to proceed. 我试图将SSH用作另一台计算机的袜子代理,然后询问用户是否要继续。 so I use:
所以我用:
proxy_cmd = "ssh -o 'StrictHostKeyChecking no' -i " + key_filename + ' -D 9998 ubuntu@' + ip_address
subprocess.Popen(proxy_cmd, shell=True, stdout=subprocess.PIPE)
if not raw_input('would you like to proceed?(y)')=='y':
sys.exit()
and I get: 我得到:
IOError: [Errno 11] Resource temporarily unavailable
I assume that's because the ssh is open and it is capturing stdin or something. 我认为那是因为ssh已打开并且正在捕获stdin或其他东西。 I just don't know how to bypass this (I have no need to send input to the ssh, I just want it open for Selenium to use later) How can I do this?
我只是不知道如何绕过此操作(我不需要将输入发送到ssh,我只希望它开放供Selenium稍后使用)我该怎么做?
If you want to keep stdin
available to your Python program, then you'll have to redirect stdin
for the ssh
process even if you have no intention of using it, with something like... 如果您想让
stdin
可用于您的Python程序,那么即使您无意使用它,也必须将stdin
重定向到ssh
进程,例如...
subprocess.Popen(proxy_cmd,
shell=True,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE)
Note that the subprocess
module will retain a reference to the Popen
object in the subprocess._active
list, but you may also want to bind the resulting Popen
object to a variable so you can perform operations on it later. 需要注意的是,
subprocess
模块将保留到参考Popen
在对象subprocess._active
名单,但你也可能要产生的绑定Popen
对象变量这样你就可以在以后的操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.