0

I want to verify an installation on a windows (XP) machine. So i want to create a .bat file that does the work.

I want to verify commands like

jruby --version

and echo "OK" if it gives reasonable output. So in pseudocode:

if( `jruby --version`.startsWith("jruby 1.5.6") then 
  echo "OK"
else
  echo "FAIL: Jruby not working!"

Any ideas on how to make that comparison in a bat file?

Jesper Rønn-Jensen
  • 106,591
  • 44
  • 118
  • 155

1 Answers1

1
@echo off
jruby --version 2>&1 | findstr /I /C:"jruby 1.5.6" > nul

if %errorlevel% == 0 (
    echo "OK"
) else (
    echo "FAIL: Jruby not working!"
)

pause
Jesper Rønn-Jensen
  • 106,591
  • 44
  • 118
  • 155
Rene Larsen
  • 1,178
  • 9
  • 16
  • Thanks Rene. I wonder about that `%errorlevel%`. Will this also work for multiple following checks, so that i can do a series of checks. One failing must not lead to the next failing. – Jesper Rønn-Jensen Mar 01 '11 at 19:30
  • Hi Jesper. You can with `%errorlevel%` decide after each command/check if you want to exit out or not, the `%errorlevel%` will get a new state after each command. Maybe you want to save the state of `%errorlevel%` in another variable, and then use the information at the end of all checks - you decide all by your self. – Rene Larsen Mar 01 '11 at 20:15