1

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

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

10 Comments

I think telnet connection cannot be automated with plink. Besides that , I'm logging in to a host that needs a specific format while entering the credentials , so a standard username and password wont work. On the other hand , why not to use Sendkeys in such way ? what is the issue ?
The main issue is that SendKeys sends the keystrokes to the foreground window. Whatever that is. So if something pops into the foreground while your VBScript is typing, the keystrokes go to an undesired location. Do not use SendKeys unless you triple-checked that no other option is available.
can you suggest another way to do it ?
I believe I already did. If for some reason you must rely on sending keystrokes you may want to take a look at AutoIt.
please "Ansgar" help me i don't know where i complain there is guy have multi account keep down vote everyday with no reason he have no idea of programming or system engineer as you moderator in this community please and professional engineer check my post and judge me and him because he do that everyday after i uncover him that he din't know vbscript and he don't know what is the instance the problem he is one of the top vbscript all time.thanks you in advance.sallam.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.