-1

python telnet conn

send {msg},

recv msg log,

1 : ^[]0;ABCD - ABCD - file=/tmp/1234^GConnected to 123.123.123.123 (test=test_ROOT_MO,Context=ABCD,ManagedElement=ABCD)^M
2 : ^M
3 : Last MO: 11668. Loaded 11668 . Total: 11669 MOs.^M
4 : ^M

5 : ^[[1;32mABCD^[[0m>

this msg(^[[1;32mABCD^[[0m>) in log , but telnet conn, and send msg

    ABCD> msg
    ABCD - ABCD - file=/tmp/1234^GConnected to 123.123.123.123 (test=test_ROOT_MO,Context=ABCD,ManagedElement=ABCD)
    Last MO: 11668. Loaded 11668 . Total: 11669 MOs.   

    *ABCD>*

last ABCD> is colorfull(green)

Q). I want find " ^[[1;32mABCD^[[0m> " (ABCD is always change)

I try under code, but failed

--> self.teln.read_until('\^[.\^[.>.*',300)

Pyo
  • 1

1 Answers1

0

With the Tcl expect I would advise:

I assume you're trying to match the prompt, and the colour codes are messing you up. I'd keep it as simple as possible: match the angle bracket and space at the end of input:
expect -re {> $}

With python's telnetlib, it appears that read_until does not work with a regular expression. I wonder if this will be sufficient:

self.teln.read_until('[0m> ', 300)

Perhaps you want read_eager() or read_very_eager() instead.

glenn jackman
  • 238,783
  • 38
  • 220
  • 352