Windows批处理文件在服务器重启后启动浏览器

时间:2016-10-28 07:22:57

标签: bash batch-file tomcat

我想创建一个批处理文件,它将启动tomcat服务器,服务器启动后,我想在浏览器中打开一个URL。

在下面的解决方案中,建议使用超时选项。

How to launch application after server startup using batch file?

还有其他更好的方法来检查tomcat是否已启动,然后我可以触发打开浏览器。

2 个答案:

答案 0 :(得分:0)

您可以使用:

wmic process list brief | find /i "tomcat"

要查看tomcat正在运行。

你也可以使用powershell:

test-netconnection -computername <name or ip> -port <port number> 
get-process | select-string <process name>

第一个命令将检查指定的端口是否正在侦听,第二个命令将检查指定的进程是否正在运行。您可以按照您认为合适的顺序使用它们并检查输出。如果输出未处于所需状态,则可以进行休眠并再次循环,直到tomcat为止。

答案 1 :(得分:0)

start "" tomcat.exe
:loop
timeout /t 1 >NUL
tasklist /FI "imagename eq tomcat.exe" | findstr /I /C:"tomcat.exe" >NUL
if errorlevel 1 goto loop
chrome.exe http://%url%

任务列表验证,如果启动程序真正运行。不要简单地相信程序正确启动

相关问题