Batch File input validation - Make sure user entered an integer

前端 未结 16 2367
抹茶落季
抹茶落季 2020-12-03 14:33

I\'m experimenting with a Windows batch file to perform a simple operation which requires the user to enter a non-negative integer. I\'m using simple batch-file techniques t

16条回答
  •  眼角桃花
    2020-12-03 15:24

    you can reinvent the wheel and grow a few white hairs doing string validation in batch, or you can use vbscript

    strInput = WScript.Arguments.Item(0)
    If IsNumeric(strInput) Then
        WScript.Echo "1"
    Else
        WScript.Echo "0"
    End If
    

    save it as checkdigit.vbs and in your batch

    @echo off
    for /F %%A in ('cscript //nologo checkdigit.vbs 100') do (
            echo %%A
            rem use if to check whether its 1 or 0 and carry on from here
    )
    

提交回复
热议问题