Domanda

I am in need of help to adding a not responding check to my .bat and restarting a server application when it is not responding. This is what I have so far.

@echo on
 tasklist /nh /fi "imagename eq javaw.exe" | find /i "javaw.exe" >nul && (
 echo Server is running.

//
I need a not responding check right afterward here. If the program is not responding,
 taskkill /f /IM server.exe
 taskkill /f /IM javaw.exe
 cd C:\Users\Administrator\Desktop
 serverstart.jar

else
exit
//

 exit
 ) || (
 echo Server process not found.
 taskkill /f /IM server.exe
 taskkill /f /IM javaw.exe
 cd C:\Users\Administrator\Desktop
 serverstart.jar
 )
 pause>nul

It is necessary for me to kill both of these process because it doesn't end eachother when it crashes apparently.

È stato utile?

Soluzione

You already managed to filter by imagename. You can also filter by Status (Running / Not Responding / Unknown):

tasklist /nh /fi "imagename eq java.exe" /fi "status eq not responding"

will give you any java.exe, which does not respond.

EDIT

well - when I think about it: I would try:

tasklist /nh /fi "imagename eq javaw.exe" /fi "status eq running` |find  /i "javaw.exe"  >nul && ( 
echo Server is running 
rem nothing to do
) || ( 
echo Server is not running or not responding
rem restart service
)
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top