Getting the result of a command with Net::Telnet

Please have a look at the following simple Ruby statement (tn is
a Net::Telnet object):

tn.login(…)
tn.cmd({‘String’ => ‘uname -n’, ‘Match’ => /[email protected]*# */}) {
puts “string received:”
puts str
}

When I run this, I see the result:

string received:
u
string received:
name -n
sb1-1
[email protected]:~#

That is, I get the response in two pieces: First the first character
only (“u”), then the rest.

Is there a way to get everything in one piece?

Or might there even be a clever way, which would let me see just
the result of the uname -n command (“sb1-1”), but neither the echoing
of “uname -n”, nor the subsequent prompt (“[email protected]:~#”)? Of
course I can easily extract the required information by myself,
but this seems such a common thing to do (send a command via telnet
and analyze what comes back) that I wonder whether there existed
an easier way to do it.

Ronald

Ronald F. wrote:

Please have a look at the following simple Ruby statement (tn is
a Net::Telnet object):

tn.login(…)
tn.cmd({‘String’ => ‘uname -n’, ‘Match’ => /[email protected]*# */}) {
puts “string received:”
puts str
}

tn.login(…)
str = tn.cmd(‘uname -n’).chop
p str

Does it works for you ?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs