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