Determine if Tomcat is running in Windows using the command prompt

后端 未结 10 1703
陌清茗
陌清茗 2020-12-15 06:24

Quite simply, how does one determine whether or not Tomcat is running in Windows, using the command prompt?

I am writing a batch script that must do this. This is

相关标签:
10条回答
  • 2020-12-15 07:12

    You could use tasklist to check if the tomcat executable is running. For example:

    @echo off
    tasklist /FI "IMAGENAME eq tomcat.exe" | find /C /I ".exe" > NUL
    if %errorlevel%==0 goto :running
    
    echo tomcat is not running
    goto :eof
    
    :running
    echo tomcat is running
    
    :eof
    

    It is also possible to check a remove server using the options /S, /U and /P. See tasklist /? for details.

    0 讨论(0)
  • 2020-12-15 07:14

    use netstat -a in command prompt.

    You'll find 8080 port listed there.

    0 讨论(0)
  • 2020-12-15 07:18

    Test the status of the Tomcat Service with the SC command. MJB already suggested to test the service status with SC, yet another batch script (without FOR loop) for testing the status:

    @ECHO OFF
    SC query tomcat5 | FIND "STATE" | FIND "RUNNING" > NUL
    IF ERRORLEVEL 1 (
        ECHO Stopped
    ) ELSE (
        ECHO Running
    )
    

    If you are not sure if the service name is tomcat5 you can list all service names with

    SC query state= all | FIND "SERVICE_NAME"
    
    0 讨论(0)
  • 2020-12-15 07:19

    Yet another option, since this is probably running as a service

    FOR /F "tokens=4 delims= " %%A IN ('SC QUERY tomcat5 ^| FIND "STATE"') DO SET status=%%A
    echo "%status%"
    

    status can be things like STOPPED, RUNNING ...

    0 讨论(0)
提交回复
热议问题