views:

102

answers:

1

In the windows shell:

echo "foo bar" | find "foo"

succeeds (i.e. errorlevel = 0). However, I want a script that fails (i.e. errorlevel <> 0) when it finds a particular word in some input text. Any ideas?

+1  A: 

A lttle trickery can emulate what you desire. Only the first three lines are required, the rest are just a test.

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
paxdiablo