嗨,我是python新手。在
我现在正在使用popen()方法开发分离ssh shell。在
"Start a shell process for running commands"
if self.shell:
error( "%s: shell is already running" )
return
cmd = [ './sshconn.py' ]
self.shell = Popen( cmd, stdin=PIPE, stdout=PIPE, stderr=STDOUT,
close_fds=True )
self.stdin = self.shell.stdin
self.stdout = self.shell.stdout
self.pid = self.shell.pid
self.pollOut = select.poll()
self.pollOut.register( self.stdout )
这个方法使用交互式.pyparamiko的demo as命令中的代码。在
^{pr2}$问题是在执行popen()时,它返回 回溯(最近一次呼叫):
File "./sshconn.py", line 43, in <module>
main()
File "./sshconn.py", line 20, in main
oldtty = termios.tcgetattr(sys.stdin)
termios.error: (22, 'Invalid argument')
我怎么解决这个问题?在
我认为一个可能的解释是
sys.stdin
没有连接到TTY(它是一个PIPE
,就像你的Popen
)一样。在如果你想要一个交互式shell,你应该和它交互。如果需要非交互式shell,理想的解决方案是调用远程程序并等待它返回成功或失败的错误代码。试着用} ,这样简单多了。在
paramiko
来代替^{相关问题 更多 >
编程相关推荐