0

I want to create a batch file which will start the tomcat server and after the server is started , I want to open a URL in browser.

In the below solution , the suggestion is to use timeout option .

How to launch application after server startup using batch file?

Is there any other better way to check if tomcat is started and then I can trigger to open the browser.

lives
  • 1,243
  • 5
  • 25
  • 61

2 Answers2

0

You can use this:

wmic process list brief | find /i "tomcat"

To see tomcat is running.

You can use powershell too:

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

First command will check if the specified port is listening and the second will check if the specified process is running. You can use them in whatever order you see fit and check the output. If the output is not in desired state, you can do sleep and loop again until tomcat is up.

Farhad Farahi
  • 35,528
  • 7
  • 73
  • 70
  • how do i use the output of the wmic command ? Is it similar to checking the errorlevel ? Sorry I dont have experience in batch commands – lives Oct 28 '16 at 20:01
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%

tasklist verify, if started program really running. Do not simply trust the program start correctly

user2956477
  • 1,208
  • 9
  • 17
  • Please learn how to [format](http://stackoverflow.com/help/formatting) code properly -- see [the edit](http://stackoverflow.com/revisions/40300897/2)... – aschipfl Oct 28 '16 at 08:30
  • Check if your tomcat exe file does not including version number e.g. "tomcat8.exe" and modify batch file accordingly. – user2956477 Oct 29 '16 at 10:10
  • While this code snippet may solve the problem, it doesn't explain why or how it answers the question. Please [include an explanation for your code](//meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers), as that really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. **Flaggers / reviewers:** [For code-only answers such as this one, downvote, don't delete!](//meta.stackoverflow.com/a/260413/2747593) – Scott Weldon Oct 31 '16 at 14:36