I'm using Parmiko to invoke an ssh shell and I would like to direct all of the input/output to a Text widget. I found this solution:
class IORedirector(object):
'''A general class for redirecting I/O to this Text widget.'''
def __init__(self,text_area):
self.text_area = text_area
class StdoutRedirector(IORedirector):
'''A class for redirecting stdout to this Text widget.'''
def write(self,str):
self.text_area.write(str,False)
# In your Tkinter Widget
sys.stdout = StdoutRedirector( self )
The problem is I'm not familiar with classes enough to make this work (no matter how simple it may be) and time is unfortunately not on my side. That being said, what is the easiest way to do this without a class definition? Could that class be converted to a general function and call it to do the redirect?
Thanks for any help.
Edit: Upon further experimenting, I altered
self.text_area.write(str,False)
to
self.text_area.insert(END,str)
This now works as print statements now appear in the text box. Now my issue is when I call interactive.interactive_shell(chan), the program crashes with
AttributeError: 'StdoutRedirector' object has no attribute 'flush'
Any ideas with this?
Edit2: I shall keep digging. Now have found this. I've added a no-op for flush and consequently get:
AttributeError: 'NoneType' object has no attribute 'settimeout'
I feel like this will be a gopher hole. Any ideas from now?
Edit 3: I will chase this to the end. Needed a (self) parameter added like def flush(self).
I'm not sure where this is going anymore so back to a simple solution of routing a Paramiko interactive shell to Text box with input and output would be great.