How do you execute multiple commands in a single session in Paramiko? (Python)

前端 未结 6 1203
礼貌的吻别
礼貌的吻别 2020-11-27 13:50
def exec_command(self, command, bufsize=-1):
    #print \"Executing Command: \"+command
    chan = self._transport.open_session()
    chan.exec_command(command)
             


        
6条回答
  •  爱一瞬间的悲伤
    2020-11-27 14:23

    Strictly speaking, you can't. According to the ssh spec:

    A session is a remote execution of a program. The program may be a shell, an application, a system command, or some built-in subsystem.

    This means that, once the command has executed, the session is finished. You cannot execute multiple commands in one session. What you CAN do, however, is starting a remote shell (== one command), and interact with that shell through stdin etc... (think of executing a python script vs. running the interactive interpreter)

提交回复
热议问题