【问题标题】:findstr exit codes/errorlevelfindstr 退出代码/错误级别
【发布时间】:2015-08-04 13:41:19
【问题描述】:

我有一个使用findstr 的程序,当找到字符串时errorlevel 返回0,当找不到字符串时errorlevel 返回1。好吧,没关系,我能应付。

问题出在我找不到任何官方文档说明每个errorlevel 对findstr 的含义。我需要知道findstr 的其他任何东西是否可以返回1 的errorlevel,或者它是否只在找不到字符串时返回1。

“官方”文档的链接是首选,如果有的话,但任何输入将不胜感激。

提前致谢!

【问题讨论】:

    标签: cmd exit-code findstr errorlevel


    【解决方案1】:

    http://ss64.com/nt/findstr.html 说:

    FINDSTR will set %ERRORLEVEL% as follows:
    
    0 (False) a match is found in at least one line of at least one file.
    1 (True) if a match is not found in any line of any file, (or if the file is not found at all).
    2 Wrong syntax 
    An invalid switch will only print an error message in error stream.
    

    【讨论】:

      【解决方案2】:

      在 FIND 命令的 Dos 6.22 帮助中有记录。

      │FIND exit codes
      │
      │The following list shows each exit code and a brief description of its
      │meaning:
      │
      │0
      │    The search was completed successfully and at least one match was found.
      │
      │1
      │    The search was completed successfully, but no matches were found.
      │
      │2
      │    The search was not completed successfully. In this case, an error
      │    occurred during the search, and FIND cannot report whether any matches
      │    were found.
      │
      │You can use the ERRORLEVEL parameter on the <If> command line in a batch
      │program to process exit codes returned by FIND.
      

      【讨论】:

      • 这是否也适用于`findstr'?
      • 是的。我搜索了 12 年的最新参考资料。我有 Dos 6.22 和 OS/2 Warp 4(它说 它返回 0 表示正常完成)。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-09-28
      • 2012-03-01
      • 2016-10-26
      • 1970-01-01
      • 1970-01-01
      • 2021-04-05
      • 2013-08-10
      相关资源
      最近更新 更多