Determine if Tomcat is running in Windows using the command prompt

后端 未结 10 1755
陌清茗
陌清茗 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:00

    I check it by calling a vb script from command line

    cscript //nologo checkurl.vbs | findstr "200"
    IF errorlevel 1 GOTO :not_running 
    

    Save the below script as checkurl.vbs and replace the ip with machines ip

    ' Create an HTTP object
    myURL = "http://10.1.1.1:8080/"
    Set objHTTP = CreateObject( "WinHttp.WinHttpRequest.5.1" )
    
    ' Download the specified URL
    objHTTP.Open "GET", myURL, False
    On Error Resume Next
    objHTTP.Send
    intStatus = objHTTP.Status
    
    If intStatus = 200 Then
        WScript.Echo intStatus
    Else
      WScript.Echo "Error Connecting"
    End If
    

    I had problems with using sc query command, because even if tomcat crashed, the service would still be shown as running where in actual the port was not accessible

提交回复
热议问题