[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[系统相关] 【求助】执行findstr未引起%errorlevel%值变化一例

已知H:\2.txt内容如下:
  1. @echo off
  2. hello there
  3. hellothere
  4. "分析 MOF 文件": C:\windows\system32\wbem\cli.mof (阶段性错误 2 )
  5. hello
  6. there
  7. hello thererere
复制代码
2.bat代码如下:
  1. set errorlevel=1
  2. echo err=%errorlevel%
  3. findstr /ic:"hello" H:\2.txt
  4. echo err1=%errorlevel%
复制代码
执行结果如下:
  1. err=1
  2. hello there
  3. hellothere
  4. hello
  5. hello thererere
  6. err1=1
  7. 请按任意键继续. . .
复制代码
【疑惑】findstr的执行,按说会导致%errorlevel%被重新赋值,在本例中,执行findstr查找成功,应该将errorlevel的值修正为0
但为什么显示的结果还是1呢?

与 path 环境变量一样,errorlevel 也属于系统环境变量,没事不要瞎自定义。

TOP

返回列表