paramiko-expect icon indicating copy to clipboard operation
paramiko-expect copied to clipboard

How to put the output we get from expect prompt in a file

Open panda2799 opened this issue 2 years ago • 2 comments

Hi sir,

I have been trying to log the output that i get on cmd through interact.expect() into a file. But file is not receiving anything. I am not able to find a proper code as well. Could you please help me with that.

Pasting my code for reference: interact.send("show full-configuration") with open('backup1'+'.txt','w') as file: for line in interact.expect("",timeout=1): file.write(line)

I am trying to fetch the fortigate configuration output. Please help me. Thanks!

panda2799 avatar Apr 24 '22 14:04 panda2799

I think something like this would do the trick:

def write_to_file(msg):
      with open('output.log', 'a') as f:
            f.write(msg)

interact = SshClientInteraction(client, output_callback=write_to_file)

fruch avatar Jun 23 '22 18:06 fruch

@panda2799 did this helped ?

fruch avatar Oct 02 '22 21:10 fruch