Now I'm trying to figure it out by set a short channel timeout.
Work flow is basically like this:
1. Start a new thread to set the channel timeout to one second or so.
2. buffer = channel. recv(256)   output += buffer in a while True: loop,
break if timeout occurs.
3. In the main thread, make the new thread join(0.5) if isAlive()
4. If it's NOT alive, process the output as you want.

It may add additional 1-2s' delay, But it doesn't matter for me. :)
Any idea to improve it?

On Sun, Feb 7, 2010 at 9:28 PM, Wan Li <wanli...@gmail.com> wrote:

>
> I have one solution for this problem:
>>
>>    def execute(self, command):
>>        """Execute the given commands on a remote machine."""
>>        channel = self._transport.open_session()
>>        channel.exec_command(command)
>>        if command.startswith("sudo"):
>>            time.sleep(1)
>>            channel.send(self.password + "\n")
>>            time.sleep(1)
>>            channel.send(self.password + "\n")
>>        output = channel.makefile('rb', -1).readlines()
>>        if not output:
>>            output = channel.makefile_stderr('rb', -1).readlines()
>>        channel.close()
>>        return output
>>
>> it's really works, but have one problem, when the sudo version is newest
>> or equal than 1.7.1, this doesn't works, i paste the output when we use
>> the last version of sudo.
>>
>> sudo: no tty present and no askpass program specified
>>
>
> Maybe we should go back to invoke_shell() call, not the open_session() one,
> isn't it?
>
> --
> >: ~
>



-- 
>: ~
_______________________________________________
paramiko mailing list
paramiko@lag.net
http://www.lag.net/cgi-bin/mailman/listinfo/paramiko

Reply via email to