Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Batch file User Input.  (Read 4073 times)

0 Members and 1 Guest are viewing this topic.

On40

    Topic Starter


    Rookie

    Batch file User Input.
    « on: February 11, 2009, 01:00:58 AM »
    Well, i lost the technique after some month's of gaming.

    I tryed to do this:

    @echo off
    title Test menu
    color F0
    :Menu
    echo Test menu.
    echo --------------
    echo 1. echo weeeeeeeeeeeeeeeeee it works
    echo 2. quit
    set /p input=Input:
    if 'input' == '1' goto wee
    if 'input' == '2' exit
    :wee
    echo weeeeeeeeeeeeeeeeee it works
    pause
    quit

    I didnt work, it just skipped everything and said wee paused and quitted. :P

    What did i do wrong?

    Carbon Dudeoxide

    • Global Moderator

    • Mastermind
    • Thanked: 169
      • Yes
      • Yes
      • Yes
    • Certifications: List
    • Experience: Guru
    • OS: Mac OS
    Re: Batch file User Input.
    « Reply #1 on: February 11, 2009, 01:48:32 AM »
    if /i %input%==1 goto :wee

    GuruGary



      Adviser
      Re: Batch file User Input.
      « Reply #2 on: February 11, 2009, 08:44:28 AM »
      I would change Carbon's code slightly.  You don't really need the /i because we are only comparing numbers. I would also add brackets (or quotes) to the comparisons, otherwise, if the user just presses [Enter] the variable would be blank and the batch file would probably exit with an error.
      Code: [Select]
      if {%input%}=={1} goto :weeAlso, I don't think QUIT is not an internal command or standard external command.  I would probably change that to
      Code: [Select]
      goto :EOF

      Carbon Dudeoxide

      • Global Moderator

      • Mastermind
      • Thanked: 169
        • Yes
        • Yes
        • Yes
      • Certifications: List
      • Experience: Guru
      • OS: Mac OS
      Re: Batch file User Input.
      « Reply #3 on: February 11, 2009, 08:45:58 AM »
      If you want the batch file to close, it does that automatically at the end of the script.
      Otherwise, the correct command is exit

      BC_Programmer


        Mastermind
      • Typing is no substitute for thinking.
      • Thanked: 1140
        • Yes
        • Yes
        • BC-Programming.com
      • Certifications: List
      • Computer: Specs
      • Experience: Beginner
      • OS: Windows 11
      Re: Batch file User Input.
      « Reply #4 on: February 11, 2009, 09:00:33 AM »
      actually, the GOTO :EOF is better- if they start the batch from the command-line, then the exit command will close that command interpreter instance on them. whereas the goto will go to the end of the file and the command interpreter will be returned control.
      I was trying to dereference Null Pointers before it was cool.

      On40

        Topic Starter


        Rookie

        Re: Batch file User Input.
        « Reply #5 on: February 27, 2009, 07:20:02 AM »
        Ok thanks :) Trying to see if it works. Man sorry for gravedigging. I just went on some skiing trip.