frankzappa77
Member
Whenever I write a batch script that provides options using 'if' statements, and input a semicolon, it terminates unexpectedly. Is there a way to prevent this?
For example:
If I type in ';' as input, the batch file will close without prompting me that '%ch% is not a valid parameter'.
I tried calling the batch file from within command prompt and it gives me this error:
Is there a way I can write the batch file so that it doesn't terminate when I have a semicolon in the input?
For example:
Code:
@echo off
:main
cls
echo Type 'p' or '1' to print a message
echo.
set /p ch=
if /I %ch%==p (
cls
echo Hello
echo.
pause
goto main
)
if %ch%==1 (
cls
echo Hello again
echo.
pause
goto main
) else (
cls
echo '%ch%' is not a valid parameter
echo.
pause
goto main
)
I tried calling the batch file from within command prompt and it gives me this error:
Code:
Type 'p' or '1' to print a message
;
( was unexpected at this time.
C:\>
My Computer
System One
-
- Manufacturer/Model
- Acer Aspire 5630
- CPU
- Intel Core 2 Duo T5500 1.66GHz 65nm 667MHz FSB 2MB L2
- Motherboard
- Acer Grapevine Intel i945GM Chipset
- Memory
- 2x1GB DDR2 333MHz
- Graphics card(s)
- Intel Integrated GMA 950 256MB
- Sound Card
- Realtek High Definition Audio
- Monitor(s) Displays
- 15.4" WXGA Acer CrystalBrite LCD 16ms
- Screen Resolution
- 1280x800
- Hard Drives
- 200GB 5400rpm Toshiba MK2035GSS ATA-7, 250GB 7200rpm Maxtor External USB Hard Drive