save vbscript to a file

2019-03-02 22:52发布

问题:

I have a batch file that contain:

@echo off

start telnet x.x.x.x 5000
cscript script_test.vbs

while script_test.vbs contains:

set OBJECT=WScript.CreateObject("WScript.Shell")
WScript.sleep 50 

'Enter username
OBJECT.SendKeys "xxxx{ENTER}" 
'Enter password
WScript.sleep 1000
OBJECT.SendKeys"xxxx{ENTER}"
WScript.sleep 1000
'First Command
OBJECT.SendKeys"COMMAND1 {ENTER}"
WScript.sleep 100

OBJECT.SendKeys " "

Noting that COMMAND1 will result an output that I need to save in a file.

How to save the output resulting from this command to a specific file by specifying its path.

回答1:

Do not use SendKeys for automating the telnet command that ships with Windows. Use a telnet command that is actually scriptable, like plink from the PuTTY suite.

plink -batch -telnet -l USERNAME -pw PASSWORD x.x.x.x COMMAND1