Sugested Additional Feature : channel.execute_in_interactive_shell('cmd')

Bug #340130 reported by Adam Grandt
2
Affects Status Importance Assigned to Milestone
paramiko
New
Undecided
Unassigned

Bug Description

It is necessary on occasion to execute a command in interactive shell. (I needed to to get access to some env vars... ) While there are many way to accomplish this I opted to run my cmd in interactive mode.
To do so I had to write this little wrapper snippet and figured it might make a good additional method for paramiko.channel.

<code>

def .execute_in_interactive_shell(self, command):

    """
        Execute a command on the server inside an interactive shell.
        If the server allows it, the channel will then be directly connected to
        the stdin, stdout, and stderr of the command being executed.

       To accomplish this we initiate a shell without getting a tty first.
    """

    if self.closed or self.eof_received or self.eof_sent or not self.active:
        raise SSHException('Channel is not open')
    m = Message()
    m.add_byte(chr(MSG_CHANNEL_REQUEST))
    m.add_int(self.remote_chanid)
    m.add_string('exec')
    m.add_boolean(True)
    m.add_string(command)
    self.event.clear()

   #### Mod starts here
    self.setblocking(0)
    self.invoke_shell()
   #### Thant it....

    self.transport._send_user_message(m)
    self._wait_for_event()

</code>

Thank you - paramiko really saved my life (well project).

Adam Grandt
<email address hidden>

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.