It's a bit tricky to read result of a command into a variable. I prefer a workaround: write the result to a temp file then read its content to a variable:
echo 42 > "%TEMP%\tmp.txt"
set /p result=<"%TEMP%\tmp.txt"
if %result% GTR 40 echo OK
Edit
Temp file is created in temp folder.