代码之家  ›  专栏  ›  技术社区  ›  Kurt Schelfthout

找到文本时失败的cmd脚本

  •  0
  • Kurt Schelfthout  · 技术社区  · 17 年前

    在windows shell中:

    echo "foo bar" | find "foo"

    失败 (即errorlevel<>0)当它在某些输入文本中找到特定单词时。有什么想法吗?

    1 回复  |  直到 13 年前
        1
  •  1
  •   paxdiablo    17 年前

    小把戏可以模仿你的欲望。只需要前三行,其余只是测试。

    c:> echo "foo bar" | find "foo"
    c:> if x%errorlevel%==x0 echo 1 | find "2"
    c:> if not x%errorlevel%==x0 echo 1 | find "1" >nul 2>nul
    c:> echo %errorlevel%
    1