Python popen()和paramiko交互式.py

2024-05-14 08:18:06 发布

您现在位置:Python中文网/ 问答频道 /正文

嗨,我是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')

我怎么解决这个问题?在


Tags: 方法pyselfcmdstdinstdouterrorshell
1条回答
网友
1楼 · 发布于 2024-05-14 08:18:06

我认为一个可能的解释是sys.stdin没有连接到TTY(它是一个PIPE,就像你的Popen)一样。在

如果你想要一个交互式shell,你应该和它交互。如果需要非交互式shell,理想的解决方案是调用远程程序并等待它返回成功或失败的错误代码。试着用paramiko来代替^{},这样简单多了。在

相关问题 更多 >

    热门问题