You are not logged in.
Pages: 1
Hi everyone, I wrote a very simple batch file, being that I'm new with if statements within batch i wanted to know how to correct this. I want my if statement to check if the user hasn't input anything and then provide a usage output. what did i do wrong?
@echo off
if "%1" == "" (
echo Usage: %0 arg1
exit /b
)
set /p option=Enter Username:
echo Your Username is %option%
echo Your secret Number is %random%
pause
cls
echo Thank you for using Joes Program %option% Enjoy your day!
pause
Offline
You should clear the variable because if you invoke it multiple times from the same CMD session it will contain the value from a previous run. Also check it after user hits Enter.
@echo off
if "%1" == "" (
echo Usage: %0 arg1
exit /b
)
set "option="
:Input
set /p option=Enter Username:
if "%option%"=="" goto :Input
echo Your Username is %option%
echo Your secret Number is %random%
pause
cls
echo Thank you for using Joes Program %option% Enjoy your day!
pause
Windows Shell Scripting and InstallShield
Offline
Pages: 1