paramiko-expect
paramiko-expect copied to clipboard
SSHClientInteraction's current_output_clean is not clean
I am using paramiko-expect on a to execute some commands and get their corresponding exit_code. The code below works perfectly fine with 0.3.0, but it does not work with the latest one. In the latest version current_output_clean
has some leftovers from the previous command.
Any pointers how to fix it or any other better way to achieve what i am trying to do?
Note: I want to run lot of commands over a period of time and I dont want to establish a ssh connection everytime i run a command, I want a way to use an existing session but just execute a command and get its output and exit code.
Thanks in Advance,
client: PK.SSHClient = PK.SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(PK.AutoAddPolicy())
client.connect(hostname=host, username=user, password=passwd, port=port)
shell = SSHClientInteraction(client, timeout=timeout, display=display, output_callback=op_callback)
shell.send("some command")
shell.expect("some_prompt>", timeout=timeout, output_callback=logger)
lines = shell.current_output_clean.strip().split('\n') # This is OK.
shell.send('echo $?')
shell.expect("some_prompt")
exit_code = int(shell.current_output_clean.strip()) # This is NOT OK!!
@SamDanielThangarajan can you have a test demonstrating this in https://github.com/fgimian/paramiko-expect/blob/master/test/test_paramiko_expect.py ?