Monday, 15 June 2009

Validate number arguments within CMD/BAT

@echo off

if "%~1" == "" (
    echo EMPTY
    goto :EOF
)

if "%~1" == "0" (
    echo ZERO
    goto :EOF
)

set /a number_var=%~1 2>nul

if errorlevel 2 (
    echo ILLEGAL
    goto :EOF
)

if %~1 neq %number_var% (
    echo ERROR
    goto :EOF
)

set number_var
goto :EOF

No comments:

Post a Comment