Bat File Input

Bat File Input

Post by John Collin » Thu, 09 Jan 2003 03:47:13



I want to write a bat file with a 'Menu'. Something like
Press 1 to do this or Press 2 to do that', and then have
the bat file act according to the user input. I can't
remember for the life of me how to do this. Thanks in
advance.

John

 
 
 

Bat File Input

Post by Yan-Hong Huang[MSF » Thu, 09 Jan 2003 15:22:04


Hello John,

It is a long long ago topic in dos age. :P I still remember that when I was
using DOS, we often think of different ways to write bat command and there
are many reference books.

I don't remember exactly it now. I think you may need to do some goto or...
However, why not just dev a simple c++ program to do so? It is also very
easy. If the command is usually changed, you can use a config file and let
c++ program to read config file first.

Best regards,
yhhuang
VS.NET, Visual C++
Microsoft

This posting is provided "AS IS" with no warranties, and confers no rights.
Got .Net?  http://www.gotdotnet.com
--------------------
!Content-Class: urn:content-classes:message


!Subject: Bat File Input
!Date: Tue, 7 Jan 2003 10:47:13 -0800
!Lines: 8

!MIME-Version: 1.0
!Content-Type: text/plain;
!       charset="iso-8859-1"
!Content-Transfer-Encoding: 7bit
!X-Newsreader: Microsoft CDO for Windows 2000
!X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
!Thread-Index: AcK2fTEejR43jcdAQ8K+D6WQcxhtJw==
!Newsgroups: microsoft.public.win32.programmer.tools
!NNTP-Posting-Host: TK2MSFTNGXA04 10.40.1.52
!Path: cpmsftngxa09!TK2MSFTNGP08!cpmsftngxa06
!Xref: cpmsftngxa09 microsoft.public.win32.programmer.tools:362
!X-Tomcat-NG: microsoft.public.win32.programmer.tools
!
!I want to write a bat file with a 'Menu'. Something like
!Press 1 to do this or Press 2 to do that', and then have
!the bat file act according to the user input. I can't
!remember for the life of me how to do this. Thanks in
!advance.
!
!John
!
!

 
 
 

Bat File Input

Post by Jan Henrik Sylveste » Thu, 09 Jan 2003 23:11:22


CHOICE (CHOICE.COM)  will return an ERRORLEVEL dependig on the key
pressed. Then you can do s.th. like this:

IF ERRORLEVEL 5 GOTO label5
IF ERRORLEVEL 4 GOTO label4
; ...
:label5
; ...
GOTO end
:label4
; ...
GOTO end
; ...
:end

You must check the highest ERRORLEVEL first, because "IF ERRORLEVEL 5"
means s.th. lile "if ERRORLEVEL is greater or equal 5".

Without command line parameters CHOICE will ask for Y/N. You can
specify the letters and optional a message text with command line
parameters.

HTH,
Jan Henrik Sylvester

On Tue, 7 Jan 2003 10:47:13 -0800, "John Collins"


>I want to write a bat file with a 'Menu'. Something like
>Press 1 to do this or Press 2 to do that', and then have
>the bat file act according to the user input. I can't
>remember for the life of me how to do this. Thanks in
>advance.

>John