batch-file - 批处理文件输入验证整数

标签 batch-file

我想告诉用户在关闭计算机之前输入他想要的分钟数,但我不知道如何避免用户输入中出现任何字母。我只想允许一个数字,否则就完成

@ECHO OFF

pushd %systemroot%
echo *{Enter the number of minutes  required before Turn off the computer then press (enter)}
set/p "x="


if %x% EQU %x% set/a z= 60*%x%
echo %z%
shutdown -s -t %z%


echo finish

最佳答案

这是另一种方法:

@ECHO OFF
pushd "%systemroot%"
:loop
"set x="
set /p "x=Enter the number of minutes required before Turn off the computer then press (enter) "
rem this allows the user to press enter to quit without doing anything
if not defined x goto :EOF
rem check for numerals only - else loop to start again
set "num="
for /f "delims=0123456789" %%a in ("%x%") do set "num=%%a"
if defined num goto :loop

set /a z=60*%x%
echo %z%
shutdown -s -t %z%

echo finish

关于batch-file - 批处理文件输入验证整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22826927/

相关文章:

batch-file - 创建批处理文件以轻松刷新网络设置?

shell - 批处理文件在 mvn 命令后停止执行

windows - 如何编写 Windows 批处理脚本以将最新文件从目录复制到新文件夹?

python - 使用 .bat 更改目录并运行 Jupyter

windows - 在 WINDOWS 上运行的 UNIX 脚本

windows - 批处理文件 :- Detect windows version and run exe file

mysql - 批处理 : "!" OPERATOR in IF-ELSE MYSQL

windows - 如何在批处理脚本中更新 %time% 变量

regex - 在 FINDSTR 中使用子模式

windows - 批处理脚本: Why does this condition evaluate to true?