paramiko python script for linux command execution

36 Views Asked by At
_stdin, _stdout,_stderr = client.exec_command("top -c")   
print(_stdout.read().decode())  
print(_stderr.read().decode())
client.close()

output: TERM environment variable not set.

i am not getting top command output, please help in advance.

2

There are 2 best solutions below

0
Philippe On BEST ANSWER

Try to use get_pty=True

_stdin, _stdout, _stderr = client.exec_command('top -c', get_pty=True)
while buffer := _stdout.read(4096):
    print(buffer.decode())
2
Alpaslan GÖKCEN On

try code shown below,

_stdin, _stdout,_stderr = client.exec_command("export TERM=xterm \n top -c")   
print(_stdout.read().decode())  
print(_stderr.read().decode())
client.close()