ziutek / telnet

Package to handle a telnet connection
Other
141 stars 60 forks source link

Read until blank line #22

Open heyitsols opened 3 years ago

heyitsols commented 3 years ago

Hello,

I am using your library as part of connecting to systems to run a command, read the output, and then run another command. The system in question doesn't have a character as its prompt (e.g. no $ or >) and as such, I can't figure out what I should be passing to the ReadUntil() function. I was using a carriage return string "\r" but this isn't always effective as the output can be multiple lines.

Have you accounted for this use case?

Many thanks

EDIT: Perhaps there is some way to define a regex pattern that is matched?

ziutek commented 3 years ago

Your problem is parsing unformatted text without clear delimiters.

This package provides only very cheap and therefore very primitive parsing functions. You can do anything you want wrapping plain Read or ReadByte methods and analyze the input text yourself.

If there is no way to detect the message boundaries from its content you can use timeouts by setting SetReadDeadline on underlying net.Conn or using another goroutine to reading from the connection and sending on a channel (use select with time.After to implement a timeout on the channel).