paramiko - How can i return stdout to value on python? -
i made script. want return stdout value on python.
but script not work.
below script.
import paramiko import sys paramiko import autoaddpolicy sip = raw_input('ip\n') sid = raw_input('id\n') spass = raw_input('pw') client = paramiko.sshclient() client.load_system_host_keys() client.set_missing_host_key_policy(autoaddpolicy()) client.connect(hostname=sip, username=sid, password=spass) stdin, stdout, stderr = client.exec_command('hostname') s_info = stdout sys.stdout.close() client.close() print (s_info)
my script occurred below error.
traceback (most recent call last): file "test.py", line 17, in print (s_info) valueerror: i/o operation on closed file
as error mentions, you're trying write stream after you've closed it. print function redirects stdout default, , you've closed here sys.stdout.close()
in order work, comment or delete line
Comments
Post a Comment