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

L

Liu Nuaadupu

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?
 
B

Brian Candler

tony said:
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)
 
T

tony Tiankoon

Brian said:
tony said:
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.
 
T

tony Tiankoon

tony said:
Brian said:
tony said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top