如何在批处理文件中请求用户输入整数

Tho*_*phe 0 windows integer cmd batch-file

我想在Windows上创建一个批处理文件,可以让用户只输入1-31之间的数字......我可以在批处理文件中稍后使用这个数字......有可能吗?

我试过这个

set /P "month=Enter the month of the year : "
findstr /i %month% %file% | sort /+24
Run Code Online (Sandbox Code Playgroud)

谢谢 :)

npo*_*aka 5

@echo off
:try_again
set /P "month=Enter the month of the year : "
echo %month%|findstr /r "[^0-9]" && (
    echo enter a number
    goto :try_again
)
::clears the leading zeroes.
cmd /c exit /b %month%
set /a month=%errorlevel%
if %month% gtr 31  (
   echo enter a number between 1 and 31
   goto :try_again
)

if %month% lss 1 (
   echo enter a number between 1 and 31
   goto :try_again
)
Run Code Online (Sandbox Code Playgroud)

  • @ThomasJomphe失败,如果用户输入类似`2xy`的东西(在你的编辑后 - npocmaka的原始代码覆盖了) (3认同)