Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #3063

Re: Telnet "More?"

From Christopher Dicely <cmdicely@gmail.com>
Newsgroups comp.lang.ruby
Subject Re: Telnet "More?"
Date 2011-04-17 09:56 -0500
Organization Service de news de lacave.net
Message-ID <BANLkTim638b6r89U_xYninSyYUab5kLfew@mail.gmail.com> (permalink)
References <0bc1be8ec871e5fbad7753c695247ddc@ruby-forum.com>

Show all headers | View raw


On Sun, Apr 17, 2011 at 12:10 AM, Eric T. <erictetz@gmail.com> wrote:
> I'm trying to use the telnet library. I don't know Ruby AT ALL
> (evaluating it side by side with Python to see which is going to be best
> for my admin chores; this is my very first script), and this has got me
> stumped:
>
>   require 'net/telnet'
>   t = Net::Telnet::new(
>      'Host'       => 'somehost.com',
>      'Prompt'     => /:.*>/,
>   )
>   out = lambda do |c| print c end
>   t.login('someusername', 'somepassword', &out)
>   t.cmd('dir', &out)
>   t.cmd('dir', &out)
>
> The second dir command hangs with the server responding "More?" Here's
> the tail end of the output log, after the first dir command:
>
>   ...
>   04/13/2011  04:21 PM    <DIR>          Searches
>   04/13/2011  04:21 PM    <DIR>          Videos
>   04/16/2011  12:54 AM             6,558 _viminfo
>                  1 File(s)          6,558 bytes
>                 13 Dir(s)  279,022,981,120 bytes free
>
>   C:\Users\foo>dir
>   More?
>
> And it just hangs there.

It looks like the server is sending something other than the default
prompt and expecting a response; you probably need to handle that
case.

If you use telnet directly (from the console, not a script) and do the
same sequence of commands, what happens?

>
> In a slightly unrelated question, I don't understand why I have to do
> this:
>
>   out = lambda do |c| print c end
>   t.login('someusername', 'somepassword', &out)
>   t.cmd('dir', &out)
>   t.cmd('dir', &out)
>
> Rather than simply this:
>
>   t.login('someusername', 'somepassword', &print)
>   t.cmd('dir', &print)
>   t.cmd('dir', &print)
>
> Seems kinda pointless to make a function which does nothing but pass
> it's arguments unaltered to another function.

Ruby is unlike Python in that, while it has functions that are objects
(e.g., Proc objects), methods (including Kernel#print) are not
functions (or objects). So you are creating a function that performs a
method call against the object that is the current value of "self"
passing that method  the same arguments that the function was called
with, not creating a function that calls a function with the same
arguments the first function is called with.

You could capture the method as a callable, function-like object with
self.method(:print) instead of an explicit lambda declaration, which
makes the difference more clear, but is somewhat less concise in this
case.

Back to comp.lang.ruby | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Telnet "More?" "Eric T." <erictetz@gmail.com> - 2011-04-17 02:10 -0500
  Re: Telnet "More?" Christopher Dicely <cmdicely@gmail.com> - 2011-04-17 09:56 -0500
    Re: Telnet "More?" "Eric T." <erictetz@gmail.com> - 2011-04-17 20:00 -0500
  Re: Telnet "More?" 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-17 17:47 -0500
    Re: Telnet "More?" "Eric T." <erictetz@gmail.com> - 2011-04-17 19:48 -0500
      Re: Telnet "More?" Christopher Dicely <cmdicely@gmail.com> - 2011-04-18 00:37 -0500
      Re: Telnet "More?" 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-19 12:21 -0500
  Re: Telnet "More?" "mouser" <invalid@invalid.com> - 2011-04-18 04:18 +0000
    Re: Telnet "More?" "mouser" <invalid@invalid.com> - 2011-04-18 04:22 +0000
  Re: Telnet "More?" Brian Candler <b.candler@pobox.com> - 2011-04-19 04:18 -0500
    Re: Telnet "More?" "mouser" <invalid@invalid.com> - 2011-04-19 16:36 +0000
      Re: Telnet "More?" Markus Fischer <markus@fischer.name> - 2011-04-19 12:12 -0500

csiph-web