Solved Batchfile IF command errorlevel

August 18, 2012 at 22:14:51
Specs: windows xp
Hey all

if command Isn't working for me
I might be doing something wrong..

In "file.txt" is the text "hello world"..

Type file.txt | findstr "hello world"
If %errorlevel% EQU 0 ( echo yes found text
) else (
Echo not found

But even if the text isn't found or not there
It still returns a errorlevel of zero which is suppose
To be when findstr works (zero means it worked)

Is this wrong ?

Maybe another way to do this ?

See More: Batchfile IF command errorlevel

Report •

August 19, 2012 at 00:09:54

So... I tried this same command on WINDOWS 7 home premium and its fine !

I have WINDOWS XP Pro, sp3 installed...

doing my head in!

please help me :(

Report •

August 19, 2012 at 03:35:33
✔ Best Answer
findstr is tricky, but not needed for this.

@echo off & setLocal enableDELAYedeXpansioN
find "hello world" < file.txt > nul
If errorlevel 1 ( echo found no text
) else (
Echo found

Life is too important to be taken seriously.


Report •

August 19, 2012 at 03:51:37
Thanks mech... I'll give it a whirl tomorrow...

Findstr is a tricky one for sure!

Report •
Related Solutions

Ask Question