batch-file - IF "71" GTR "7000" 为真
问题描述
根据我的代码,如果%~1
大于7000
,请转到ExceedError
IF "%~1" GTR "7000" GOTO ExceedError
内容ExceedError
:
ECHO Value exceeded the maximum value. See help file.
EXIT /B
但这发生了:
...modules>If "71" GTR "7000" GOTO ExceedError
...modules>Echo Value exceeded the maximum value. See help file.
Value exceeded the maximum value. See help file.
...modules>exit /B
发生了什么?有什么不对?
解决方案
你已经用双引号括住了参数,这会强制进行字符串比较。要比较数字,请尝试不使用引号:
IF %~1 GTR 7000 GOTO ExceedError
如果您想防止错误,您可以再添加一行:
set /a "_number=%~1" >nul 2>&1 || set "_number=0"
IF %_number% GTR 7000 GOTO ExceedError
如果输入错误,您会将值与0
默认值进行比较。如果需要,您可以更改它
推荐阅读
- spring-integration - Spring集成org.springframework.integration.MessageTimeoutException处理
- batch-file - find specified numbers in text file
- node.js - AWS S3 putObject 回调未触发
- r - 从观察函数传递数据以下载
- python - 使用 Python 数据框从 csv 文件更新数据
- caching - 当键存在时,CakePHP 3.x ORM 不使用缓存数据
- javascript - jQuery验证只工作一次问题
- android - Generate pdf format and append data
- angular - 如何在 Angular 6 应用程序内的 Web 组件中嵌入 Angular 6 组件
- python - 部署到 Azure 时 Flask Dance 超时