Need help adding not responding check to batch file

て烟熏妆下的殇ゞ 提交于 2019-12-13 12:51:56

问题


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.


回答1:


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
)


来源:https://stackoverflow.com/questions/20639184/need-help-adding-not-responding-check-to-batch-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!