大家好,又见面了,我是你们的朋友全栈君。
将此下面的代码保存到一个.txt文件中,然后将后缀名命名为.vbs,再然后双击运行即可。
注意要修改的地方:
1.检查tomcat是否挂掉的访问路径,即下面代码中的:http://localhost:8080?a=” & now
2.一定要先切到bat所在目录 WshShell.CurrentDirectory=”D:\Program Files\apache-tomcat-9.0.10-windows-x64\apache-tomcat-9.0.10\bin\”,否则导致闪退
3.WshShell.Run cmd /c “& Chr(34) & shutdown & Chr(34) ,先shutdown再startup
on error resume Next
Dim a
a = True
set WshShell = WScript.CreateObject("WScript.Shell")
set fso=createobject("scripting.filesystemobject")
Do While a
set http = CreateObject("Microsoft.XMLHTTP")
http.open "GET","http://localhost:8080?a=" & now,false
http.send
if http.Status <> 200 Then
'一定要先切到bat所在目录
WshShell.CurrentDirectory="D:\Program Files\apache-tomcat-9.0.10-windows-x64\apache-tomcat-9.0.10\bin\"
shutdown="D:\Program Files\apache-tomcat-9.0.10-windows-x64\apache-tomcat-9.0.10\bin\shutdown.bat"
WshShell.Run "cmd /c "& Chr(34) & shutdown & Chr(34)
WScript.Sleep(5000)
startup="D:\Program Files\apache-tomcat-9.0.10-windows-x64\apache-tomcat-9.0.10\bin\startup.bat"
WshShell.Run "cmd /c"& Chr(34) & startup & Chr(34)
if (fso.fileexists("C:\tomcat重启记录文件.txt")) then
'打开文件,参数1为forreading,2为forwriting,8为appending
set file=fso.opentextfile("C:\tomcat重启记录文件.txt",8,true)
file.writeline "tomcat在"
file.writeline now
file.writeline "自动重启了一次"
ts.writeblanklines 2
file.close
else
'创建文件,参数1为forreading,2为forwriting,8为appending
set file=fso.createtextfile( "C:\tomcat重启记录文件.txt",2,ture)
'写入文件内容,有三种方法:write(x)写入x个字符,writeline写入换行,writeblanklines(n)写入n个空行
file.writeline "tomcat在"
file.writeline now
file.writeline "自动重启了一次"
file.writeblanklines 2
file.close
end if
end if
WScript.Sleep(30000)
loop
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/163638.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...