Got a simple script that executes a command to a server - briefly:
//Create shell
set WshShell=CreateObject("WScript.Shell")
WshShell.run "cmd.exe"
//send commands
WshShell.SendKeys "telnet IP_ADDRESS"
WshShell.Sendkeys "dir"
Server offers feedback which I want to capture. I just need to capture the first line into a variable, and then just print that variable out to confirm.
Can you help? Thanks.
It might not be the best method, but worked for me:
Windows telnet command can save the output in client side using -f arguments. Therefore, you could use:
and at the end of your script, simply process the content of telnet.out
Do not use the Windows
telnet
client for automation purposes. Thetelnet
client that ships with Windows was made for interactive use only.I'd use
plink
(from the PuTTY suite) in batch mode for this:The tool doesn't require installation, so you can simply deploy it alongside your script.
Run it either in a batch file using
head
/tail
, or in a VBScript using theExec
method, so you can read from StdOut: