3

hi i want to make ssh connection and parse some datas. Im using paramiko and here is part of my code:

ssh=ssh_pre.invoke_shell()
ssh.send("display ospf peer brief \n")
output = ssh.recv(10000)

everything work until this part

buf=StringIO.StringIO(output)
for lines in buf.read()
    print lines

this code print chars line by line . I want to print lines . what should i do?

2
  • You want write all buffer in one shot. Isn't it? Commented Dec 7, 2014 at 18:24
  • my main purpose i will read what is return from the server and find specific line. for example the line includes 'apple'. if i write line by line i believe i can do what i want Commented Dec 7, 2014 at 18:56

1 Answer 1

2

The issue is StringIO.read() returns a string, a sequence of characters, not lines. Try doing this:

buf=StringIO.StringIO(output)
for lines in buf.read().split("\n"):
    print lines

This will split your buffer by newlines and create a list of each line, rather than looping over each individual character in the string.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.