Computer Hope

Microsoft => Microsoft DOS => Topic started by: On40 on February 11, 2009, 01:00:58 AM

Title: Batch file User Input.
Post by: On40 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?
Title: Re: Batch file User Input.
Post by: Carbon Dudeoxide on February 11, 2009, 01:48:32 AM
if /i %input%==1 goto :wee
Title: Re: Batch file User Input.
Post by: GuruGary 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
Title: Re: Batch file User Input.
Post by: Carbon Dudeoxide 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
Title: Re: Batch file User Input.
Post by: BC_Programmer 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.
Title: Re: Batch file User Input.
Post by: On40 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.