how to judge the command result of batch by Net::telnet

Discussion in 'Ruby' started by Liu Nuaadupu, Jan 13, 2010.

  1. Liu Nuaadupu

    Liu Nuaadupu Guest

    telnet = Net::Telnet::new("Host" => "192.168.0.16",
    "Timeout" => 10,
    "Prompt" => /[$%#>] \z/n)
    telnet.login("username", "password") { |c| print c }
    result = telnet.cmd("c:\test.bat")
    telnet.close

    how to judge the result of the batch?
    If from the result variable you must know the true result.
    If from the command [telnet.cmd("echo %ERRORLEVEL")],to make sure that
    there is not any exit command in the windows batch script.
    have any other good idears?
    --
    Posted via http://www.ruby-forum.com/.
     
    Liu Nuaadupu, Jan 13, 2010
    #1
    1. Advertisements

  2. tony Tiankoon wrote:
    > If from the command [telnet.cmd("echo %ERRORLEVEL")],to make sure that
    > there is not any exit command in the windows batch script.


    Yes, that's basically what you'll need to get it back from telnet.

    However, if the server has sshd running then it's possible to execute a
    command remotely and get the command status back properly.

    Ruby's Net::SSH provides a rather awkward API unfortunately, but you
    could copy the example of "vlad" and just shell out to local ssh command
    (or pssh.exe if it's a Windows client)
    --
    Posted via http://www.ruby-forum.com/.
     
    Brian Candler, Jan 13, 2010
    #2
    1. Advertisements

  3. Brian Candler wrote:
    > tony Tiankoon wrote:
    >> If from the command [telnet.cmd("echo %ERRORLEVEL")],to make sure that
    >> there is not any exit command in the windows batch script.

    >
    > Yes, that's basically what you'll need to get it back from telnet.
    >
    > However, if the server has sshd running then it's possible to execute a
    > command remotely and get the command status back properly.
    >
    > Ruby's Net::SSH provides a rather awkward API unfortunately, but you
    > could copy the example of "vlad" and just shell out to local ssh command
    > (or pssh.exe if it's a Windows client)


    thank you very much Brain! before that I have known that ssh could get
    the return status and result of the batch.I just want to know is there
    any good idear of getting the result of batch with exit command. It
    seems that if you want to get the return status and result of batch,you
    cannot use telnet to excute the batch with exit command(with out \B
    option) in remote windows server.
    --
    Posted via http://www.ruby-forum.com/.
     
    tony Tiankoon, Jan 17, 2010
    #3
  4. tony Tiankoon wrote:
    > Brian Candler wrote:
    >> tony Tiankoon wrote:
    >>> If from the command [telnet.cmd("echo %ERRORLEVEL")],to make sure that
    >>> there is not any exit command in the windows batch script.

    >>
    >> Yes, that's basically what you'll need to get it back from telnet.
    >>
    >> However, if the server has sshd running then it's possible to execute a
    >> command remotely and get the command status back properly.
    >>
    >> Ruby's Net::SSH provides a rather awkward API unfortunately, but you
    >> could copy the example of "vlad" and just shell out to local ssh command
    >> (or pssh.exe if it's a Windows client)

    >
    > thank you very much Brain! before that I have known that ssh could get
    > the return status and result of the batch.What I just want to know is that is > there any good idear of getting the result of batch with exit command. It
    > seems that if you want to get the return status and result of batch,you
    > cannot use telnet to excute the batch with exit command(with out \B
    > option) in remote windows server.


    see the help information in windows
    >help exit

    you will get the details.
    --
    Posted via http://www.ruby-forum.com/.
     
    tony Tiankoon, Jan 17, 2010
    #4
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jim Isaacson
    Replies:
    5
    Views:
    821
    Default User
    Nov 5, 2004
  2. J.Ram
    Replies:
    7
    Views:
    842
  3. Pavel
    Replies:
    7
    Views:
    780
    Pavel
    Sep 19, 2010
  4. Lakshmi Sreekanth

    i = 10; result = ++i - --i; How result become ZERO

    Lakshmi Sreekanth, Sep 21, 2010, in forum: C Programming
    Replies:
    52
    Views:
    1,554
    Nick Keighley
    Sep 23, 2010
  5. Mr. Buffoon
    Replies:
    4
    Views:
    465
    Eric Sosman
    Sep 23, 2010
  6. Michael Tan
    Replies:
    32
    Views:
    1,568
    Ara.T.Howard
    Jul 21, 2005
  7. Carcarius
    Replies:
    0
    Views:
    470
    Carcarius
    Dec 6, 2007
  8. Amit Tomar
    Replies:
    6
    Views:
    313
    Jeremy Bopp
    Oct 16, 2010
Loading...