Search code examples
shellbatch-filespring-batch-admin

How to verify tomcat is started successfully using batch script?


Have prepared a batch script to automate the build process. Was successfully able to figure out the success and failures of build using ant in batch script (%ERRORLEVEL%), accordingly displayed the message box with proper message.

Based on ant success have executed command to startup tomcat server, but how do i come to know in batch script whether it has been started or failed?

Your help is highly appreciated.!!

Thanks.


Solution

  • @echo off
    
    call :is_running svchost.exe
    echo %errorlevel%
    
    call :is_running explorer.exe
    echo %errorlevel%
    
    call :is_running tomcat.exe
    echo %errorlevel%
    
    exit /b   
    
    :is_running
    tasklist^
     /fi "IMAGENAME eq %~1"^
     /fi "STATUS eq running"^
     /nh 2>nul | find "%~1" >nul || exit /b 1
    exit /b 0
    

    This calls a label named is_running and runs tasklist to find the ImageName running. If not running then errorlevel 1 is set. Added a few processes to test to display if it is working well.

    Use the command tasklist /? for help.