Wrox Programmer Forums
Forum and Wrox.com Feedback Post your suggestions for improving the Forums or Wrox.com or questions for the staff here. "Where can I find the code for my book?"
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Forum and Wrox.com Feedback section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old May 16th, 2005, 10:44 AM
Registered User
Join Date: May 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Need Help with DOS batch file ..

I know this is is an inappropriate place to post and I am sorry .. I couldn't find the general discussions thread ..

I am writing a batch file to automatically run some commands by telnetting to a network device. Everything goes fine until the device asks for input from the user.

E.g "Press any key to continue .. "
    "Press enter to continue .. "


The program then waits for the user input.

So I am forced to manually press the keyboard in order for the batch file to continue.

What I want to know is:

How do I simulate the "Enter" key press in my batch program?

P.S: I did googling today on this subject but they all recommend using the "CON" command with fc command. I am running windows 2000 and my DOS does not support the "CON" command.

Thanks for all the help in advance.

  #2 (permalink)  
Old May 17th, 2005, 04:40 AM
Friend of Wrox
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post

You can put the inputs you need into a separate text file, then use that as input by using the < syntax
For example, if you need to press Enter key:
- open Notepad with a new text file
- press the Enter key
- save the new file (say call it enter.txt) in the same folder as your bat file
-use the file as input like this from the command-line:
yourbatfile < enter.txt

  #3 (permalink)  
Old May 17th, 2005, 09:13 PM
Registered User
Join Date: May 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts

Thanks phil,

This is my situation.

I have about 20 network devices to manage.

Whenever there is some common change in setting, I have to log on to each and every device and reconfigure.

What I am trying to do is (cos i'm lazy), I want to create a script to automatically log in to a device and execute commands and then log off and login to the next device .. etc .. all auto.

So using batch file, I am able to start telnet. BUT as I learnt over the past few days, DOS is not optimised for interfacing with devices (thanks ASBO). Thus I cannot execute telnet commands.

So I also tried Hyperterminal. You can prepare text files with the necessary commands before hand and after logging in to a device, let the file run. It is WAY faster than typing by hand all your usual commands.

However, I still have to create a new connection each time. I want to automate that too.

Currently I am researching telnet clients with scripting facility. CRT is popular in my office, however it has limited scripting ability. Then I found TN 3270 yesterday. It seems to be meeting my expectations, but I haven't wrote the script yet.

I'll welcome any suggestions. Thanks.
  #4 (permalink)  
Old May 22nd, 2005, 09:09 AM
Registered User
Join Date: May 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts

anybody used a telnet client with scripting facility before? like TN3270?

  #5 (permalink)  
Old May 26th, 2005, 03:54 AM
Registered User
Join Date: May 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts

Hi guys .. worked on it yesterday and today and it works.
I used three files. One Batch file, two script files for the telnet client
Thanks for all the help ..

::How it works:
:: .Batch file is run
:: .Batch File runs TN3270
:: .Opens Telnet connection to one address and calls a script (passwords.txt)
:: .Passwords.txt contains individual commands for each connection
:: Besides password, other specific commands such as banner can be specified here
:: .TN3270 runs passwords.txt
:: .looks up the list of passwords and logs in to the open connection
:: .calls the 'common commands script' -> cmds.txt
:: .Cmds.txt contains the common commands to be executed for ALL the devices
:: .TN3270 executes the commands found in cmds.txt
:: .execution is passed back to passwords.txt which exits TN3270
:: .excution is passed back to batch file
:: .Batch file opens the second connection using TN3270
:: .The process is repeated
:: .When all devices have been contacted, the batch file closes DOS window.
  #6 (permalink)  
Old August 31st, 2007, 06:51 AM
Registered User
Join Date: Aug 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts

Hi Arul,

Actually, I am also looking to run some commands on a linux machine after connecting through the telnet. I want to do this from a WINDOWS batch file.
My requirement is actually like this - Run a batch file which opens a telnet connection to a linux machine, run some commands in the telnet and then close the telnet connection.

Whenever I try to open a telnet connection from a batch file, it is asking for the username and password. Is there a way we can pass the username and passwords to the telnet window?

Also, in case we are able to login, how can we execute the commands in the telnet from our batch file?

It would be great if you could share your batch file with me.

My email ID is rayulu@gmail.com

Thanks in advance,

Similar Threads
Thread Thread Starter Forum Replies Last Post
Run a MS DOS Batch file from Excel VBA Louh Excel VBA 1 March 4th, 2008 10:02 PM
View txt File as DOS Format suresh.cgmohan VB How-To 2 September 27th, 2006 07:40 AM
Telnet dos batch file sridharaiyer Need help with your homework? 0 August 25th, 2006 03:38 PM
Batch File Allan320 Access 10 June 8th, 2006 06:46 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.