找到文本时失败的cmd脚本
-
03-07-2019 - |
题
在windows shell中:
echo "foo bar" | find "foo"
成功(即errorlevel = 0)。但是,当我在某些输入文本中找到特定单词时,我想要一个失败的脚本(即errorlevel <!> lt; <!> gt; 0)。有什么想法吗?
解决方案
一点点诡计可以模仿你想要的东西。只需要前三行,其余的只是一个测试。
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
不隶属于 StackOverflow