Link to home
Start Free TrialLog in
Avatar of cantoris
cantorisFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Batch (CMD) file issue within expanded IF construct

Hi,

I have the following method of checking a file version working:
filever.exe /B /A /D "C:\Program Files\Folder\File.exe" | find "1.1.1.1" >nul
If '%errorlevel%'=='0' Goto DoSomething

Open in new window

But it doesn't work if I do it inside an expanded IF block like this:
if exist "C:\Program Files\Folder\File.exe" (
   filever.exe /B /A /D "C:\Program Files\Folder\File.exe" | find "1.1.1.1" >nul
   if '%errorlevel%'=='0' (
      rem Something here
   ) else (
      rem Something here
   )
) else (
   rem Something here
)

Open in new window

It no longer does the version match correctly.  The %errorlevel% is always 0.  
I tried redirecting the output of the filever.exe (without the pipe) to a text file and it was as expected.
I then tried redirecting the output of the find.exe to a text file and there was no output.

It's as though the piping to the FIND command no longer works inside the IF construct.  Any idea why?  Thanks!
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cantoris

ASKER

Perfect, thanks.  Not seen that feature before!