Batch Files

This is a discussion on Batch Files within the Tech Board forums, part of the Community Boards category; Hurray! Hundredth post! Well, anyways. If you write a batch file, say this is the "code": Code: @echo off cls ...

  1. #1
    Rabite SirCrono6's Avatar
    Join Date
    Nov 2003
    Location
    California, US
    Posts
    269

    Batch Files

    Hurray! Hundredth post! Well, anyways. If you write a batch file, say this is the "code":

    Code:
    @echo off
    cls
    :Menu  
      echo 1: Print Hello!
      echo 2: Exit
      CHOICE/C:12
        IF ERRORLEVEL 2 GOTO :End
        IF ERRORLEVEL 1 GOTO :Hello
    
    :Hello
      cls
      echo Hello!
      pause
      cls
      GOTO :Menu
    
    :End
    When you do the CHOICE it automatically prints [1,2]?
    Is there a way to prevent it from doing that? I know how to put my own prompt before that appears, but do I have to have that part appear too?

    - SirCrono6
    From C to shining C++!

    Great graphics, sounds, algorithms, AI, pathfinding, visual effects, cutscenes, etc., etc. do NOT make a good game.
    - Bubba

    IDE and Compiler - Code::Blocks with MinGW
    Operating System - Windows XP Professional x64 Edition

  2. #2
    5|-|1+|-|34|) ober's Avatar
    Join Date
    Aug 2001
    Posts
    4,429
    I don't know much about batch files, but can you do something like that?? Batch files are sequential and will not wait for you to make a choice, AFAIK. That's why they are called batch files... they do a batch task... they are not meant for user interaction unless you're doing something like FTP where you need to enter a password, and even then, I think you have to put the password in the batch file.

    Why not write a simple C program to do that you want?

  3. #3
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Actually you can get user input on .bat files.

    Back in the DOS 5 days I cade a menu system setup that multi layered and multi colored. Was pretty cool. The problem is that MS has removed a lot of the commands that make it work with the newer editions.

    For the batch file I got an unreconized command for CHOICE

  4. #4
    Registered User khpuce's Avatar
    Join Date
    May 2003
    Posts
    165
    Originally posted by Thantos
    Actually you can get user input on .bat files.

    Back in the DOS 5 days I cade a menu system setup that multi layered and multi colored. Was pretty cool.
    I did the same thing about 12 years ago. I am pretty sure I still have the codes (printed) somewhere in my house because I loved that one.

    IF ERRORLEVEL 2 GOTO :End
    IF ERRORLEVEL 1 GOTO :Hello
    I can't remember exactly but think you need to put it in this way -

    IF ERRORLEVEL ==2 GOTO :End
    IF ERRORLEVEL ==1 GOTO :Hello
    Last edited by khpuce; 03-09-2004 at 10:22 AM.

  5. #5
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    I think this is what you're looking for:
    Code:
    REM Replace your CHOICE Choose one /C:12 line with
    REM CHOICE /C:12 /n (no prompt, i think)
    REM
    REM or these 2 lines:
    REM echo Choose an option
    REM CHOICE /C:12 >NUL
    
    @echo off
    cls
    :Menu  
      echo 1: Print Hello!
      echo 2: Exit
      CHOICE /C:12
        IF ERRORLEVEL 2 GOTO :End -- you don't need the colons here, you do below though
        IF ERRORLEVEL 1 GOTO :Hello
    
    :Hello
      cls
      echo Hello!
      pause
      cls
      GOTO :Menu
    
    :End
    http://www.csulb.edu/~murdock/choice.html
    http://www.csulb.edu/~murdock/dosindex.html - for more commands
    The world is waiting. I must leave you now.

  6. #6
    Registered User
    Join Date
    Mar 2004
    Posts
    536
    Originally posted by Thantos
    Actually you can get user input on .bat files.

    ---stuff snipped from Thantos's reply---

    For the batch file I got an unreconized command for CHOICE

    For Windows XP, you can use SET

    Look here:
    http://www.computing.net/dos/wwwboard/forum/13909.html


    Dave

  7. #7
    Its not rocket science vasanth's Avatar
    Join Date
    Jan 2002
    Posts
    1,683
    wow. i though i knew most of the DOS stuff.. Looks like i am wrong..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 07-24-2008, 09:02 AM
  2. Windows Vista Batch Files
    By Trennto in forum Windows Programming
    Replies: 2
    Last Post: 07-02-2008, 09:30 AM
  3. Program Deployment and DLL/OCX Files?
    By dfghjk in forum C++ Programming
    Replies: 5
    Last Post: 06-16-2008, 02:47 AM
  4. help running batch files
    By xxwerdxx in forum Tech Board
    Replies: 5
    Last Post: 09-25-2005, 12:58 PM
  5. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 03:30 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21