Specialty Forums
Security and Virus
General Hardware
CPUs/Overclocking
Networking
Digital Photo/Video
Office Software
PC Gaming
Console Gaming
Programming
Database
Web Development
Digital Home

General Forums
Windows XP
Windows Vista
Windows 95/98
Windows Me
Windows NT
Windows 2000
Win Server 2008
Win Server 2003
Windows 3.1
Linux
PDAs
BeOS
Novell Netware
OpenVMS
Solaris
Disk Op. System
Unix
Mac
OS/2

Drivers
Driver Scan
Driver Forum

Software
Automatic Updates

BIOS Updates

My Computing.Net

Solution Center

Free IT eBook

Howtos

Site Search

Message Find

RSS Feeds

Install Guides

Data Recovery

About

Home
Reply to Message Icon Go to Main Page Icon

Need Help with DOS batch file ..

Original Message
Name: arul20
Date: May 16, 2005 at 09:36:21 Pacific
Subject: Need Help with DOS batch file ..
OS: win 2000
CPU/Ram: _
Comment:
Hi 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 .. "
Or
"Press enter to continue .. "

etc

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.




Report Offensive Message For Removal


Response Number 1
Name: Mechanix2Go
Date: May 16, 2005 at 10:10:57 Pacific
Subject: Need Help with DOS batch file ..
Reply: (edit)
Hi,

CON is not a command. It is a device defined by the OS.

Try this:

::==
@echo off
echo.>0d0a
type 0d0a
::==

M2


If at first you don't succeed, you're about average.


Report Offensive Follow Up For Removal

Response Number 2
Name: Mechanix2Go
Date: May 16, 2005 at 10:14:10 Pacific
Subject: Need Help with DOS batch file ..
Reply: (edit)
Or this:

::==
@echo off
echo.
::==

M2


If at first you don't succeed, you're about average.


Report Offensive Follow Up For Removal

Response Number 3
Name: arul20
Date: May 16, 2005 at 22:29:39 Pacific
Subject: Need Help with DOS batch file ..
Reply: (edit)
Thanks M2 for the prompt reply ..

I just tried it out and it stores the CR. But can u elaborate more on this series of commands?

For example,

1. Why do you put the dot after echo?
2. Why do you pipe to 0d0a?
3. Why doesn't 0d0a have a file extention?

Thank You M2 for sharing your knowledge!



Report Offensive Follow Up For Removal

Response Number 4
Name: Mechanix2Go
Date: May 16, 2005 at 23:57:08 Pacific
Subject: Need Help with DOS batch file ..
Reply: (edit)
With echo off, when you:

echo.

it puts out a 'blank line' followed by 0d0a [CRLF] which is what you get by pressing ENTER.

Don't know if this will help telnet.

Let us know how it goes with your script.

M2


If at first you don't succeed, you're about average.


Report Offensive Follow Up For Removal

Response Number 5
Name: arul20
Date: May 17, 2005 at 00:12:17 Pacific
Subject: Need Help with DOS batch file ..
Reply: (edit)
Hi M2,

I tried out echo.| on commands such as DATE and PAUSE. They worked fine.

However, telnet.exe is a separate program stored in the root directory. It also has its own commands which DOS doesn't recognise. (OPEN, CLOSE .. etc)

I tried out using pipe to telnet but DOS is not able to send any keys to telnet once telnet starts up.

HOW? Is there a way for my batch file to send commands to the telnet program?

If not can I use any other method?

I can maybe use hyperterminal, but the problem I face with hyperterminal is that I need to use the GUI to log off one connection and create a new connction. I want to automate the process so that the program will connnect to several network devices and execute commands.

Any suggestions?

Thank You.


Report Offensive Follow Up For Removal


Response Number 6
Name: Mechanix2Go
Date: May 17, 2005 at 00:30:26 Pacific
Subject: Need Help with DOS batch file ..
Reply: (edit)
I don't think it's a DOS problem.

Seem like telnet will only take two command line parameters; host & port.

No obvious way to script it.

M2


If at first you don't succeed, you're about average.


Report Offensive Follow Up For Removal

Response Number 7
Name: arul20
Date: May 17, 2005 at 19:05:34 Pacific
Subject: Need Help with DOS batch file ..
Reply: (edit)
Thank you again M2,

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.


Report Offensive Follow Up For Removal

Response Number 8
Name: FishMonger
Date: May 17, 2005 at 22:28:23 Pacific
Subject: Need Help with DOS batch file ..
Reply: (edit)
I suggest looking at some of the other scripting languages such as VB or Perl. Of course, my recomendation is Perl. Take a look at the documentation for this Perl module (Net::Telnet). If you like, I can write the script for you, as long as it's within reason.

http://search.cpan.org/~jrogers/Net-Telnet-3.03/lib/Net/Telnet.pm


Report Offensive Follow Up For Removal

Response Number 9
Name: Mechanix2Go
Date: May 17, 2005 at 22:29:36 Pacific
Subject: Need Help with DOS batch file ..
Reply: (edit)
Hi,

I just looked at jyperterminal.

I don't see how or where to create / use a script.

Give me some clues and I'll work on it.

M2


If at first you don't succeed, you're about average.


Report Offensive Follow Up For Removal

Response Number 10
Name: arul20
Date: May 18, 2005 at 00:05:29 Pacific
Subject: Need Help with DOS batch file ..
Reply: (edit)
Thanks Fishmonger and M2.

Fishmonger, I do not know Perl. You suggested VB also. I'll take a look at it and post the result back in a few days ok?

M2, I also do not know any way to script for HyperTerminal.

However there is another way to speed up your work. Save your usual commands line-by-line in a text file.

click on " Transfer -> Send Text File.. ".

It will load and run all the commands stored in the text file.

Right now I am trying out TN3270 Plus. It is another telnet client but has a good scripting feature also.

What I like about TN3270 is:
-You can automate login using scripts
-You can execute windows commands
-It is possible to have multiple sessions
-Logging capabilities

These are some of the stuff I've found so far .. finding more ..

A colleague also suggested VB, so most probably I will be using TN3270 or Visual Basic.

Anyhow, I will post when a new development occurs (or a new problem).

Thanks M2 for your time.



Report Offensive Follow Up For Removal

Response Number 11
Name: Mechanix2Go
Date: May 18, 2005 at 00:24:17 Pacific
Subject: Need Help with DOS batch file ..
Reply: (edit)
Hi,

Dumb question of the day:

Could you use ftp to send a BATCH or other script, than have the remote machine run the script?

w2k ftp _CAN_ be scripted. I discovered this by accident. The "help" in ftp is no help.

M2


If at first you don't succeed, you're about average.


Report Offensive Follow Up For Removal

Response Number 12
Name: arul20
Date: May 18, 2005 at 00:40:47 Pacific
Subject: Need Help with DOS batch file ..
Reply: (edit)
I dun know M2. I have never worked with ftp before (other than downloading from ftp servers).

Report Offensive Follow Up For Removal

Response Number 13
Name: FishMonger
Date: May 18, 2005 at 10:09:43 Pacific
Subject: Need Help with DOS batch file ..
Reply: (edit)
The ftp approach seems a little odd but it might work.

Using an actuall scripting language instead of a macro in a telnet GUI client would be best. There are a number of advantages to using Perl. To name a few, a Perl script would be shorter, cleaner, and easier to write than a VB script (even for someone that is brand new to Perl) as well as being platform independant.

Let me know if you change your mind about using Perl.


Report Offensive Follow Up For Removal

Response Number 14
Name: arul20
Date: May 18, 2005 at 23:42:03 Pacific
Subject: Need Help with DOS batch file ..
Reply: (edit)
Fishmonger,

"shorter, cleaner, and easier to write than a VB script"?

I thought vb was the easiest to learn and use! I definitely would want to use Perl if it is easier. How should I start?


Report Offensive Follow Up For Removal

Response Number 15
Name: arul20
Date: May 22, 2005 at 07:08:32 Pacific
Subject: Need Help with DOS batch file ..
Reply: (edit)
anybody used a telnet client with scripting facility before? like TN3270?


thanks


Report Offensive Follow Up For Removal

Response Number 16
Name: arul20
Date: May 26, 2005 at 01:54:25 Pacific
Subject: Need Help with DOS batch file ..
Reply: (edit)
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.


Report Offensive Follow Up For Removal



Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Need Help with DOS batch file .. 

Comments:

 
  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 


Data Recovery Software




Slow boot time

Trasnferring Documents from old HD

My k8T Neo-v usb's aren't working!

Date Modified = Date Created Time

system files on removable harddrive


The information on Computing.Net is the opinions of its users. Such opinions may not be accurate and they are to be used at your own risk. Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE

All content ©1996-2007 Computing.Net, LLC