Denis
Denis

Reputation: 664

findstr for executing a command if str does not contain 169

I am new to batch files and have seen several posts about findstr but could not get it to find a 169 inside a string which contains an IP address

    set Foo=169.254.100.1
    SET Foo|findstr /i 169
    if ERRORLEVEL 1 (echo it doesnt contain 169, do launch) else (echo it contains 169, don't do launch)

)

Foo contains 169 as you can see, but when I do findstr, it returns 1 and shows "it doesnt contain 169, do launch"

Could anybody see what is wrong here?

Upvotes: 0

Views: 169

Answers (1)

Aacini
Aacini

Reputation: 67226

May I suggest another way to achieve this test that does not use findstr?

set Foo=169.254.100.1
if "%Foo:169=%" equ "%Foo%" (
   echo it doesnt contain 169, do launch
) else (
   echo it contains 169, don't do launch
)

Upvotes: 1

Related Questions