简体   繁体   中英

Windows bat file how to verify output of a command

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?

@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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM