How to launch a web server and point the browser to it when it finishes?
I am writing a windows batch file to do the following things:
- Display a picture in the middle of the screen, showing the beautiful icon of my software.
- Kick of the launch of the web server.
- Finish displaying the picture.
- Point the browser to the start page.
I have already know how to do it in step 2 and 4. However, I have the following questions in writing the windows batch file: 1. How do I know that the launch of the web server is finished, taking jetty as the example? 2. How do I display a picture and stop displaying it when I want to?
Here is what I have got so far:
::here I would like to display the picture
start javaw -jar start开发者_开发问答.jar ::Starting jetty here
::here I would like to stop displaying the picture
start http://localhost:8080/myApp ::Pointing the browser to the page
Thank you in advance for your help.
I don't know how well you know batch fiels, but if it's a closer match to your skill set, it might be easiest that you write a small java program to repeatedly poll the port of the webserver until you can make a connection. You can then invoke that program from the batch file - use call
rather than start
, so that the batch waits until your polling program has finished.
If you want to implement using just batch commands, you can use the [NETSTAT][1]
command to write a list of ports being listened on to a file. Use FIND to search the file to see if your web server port is in the list. If the port is not found, repeat.
Parsing the output of netstat
might be tricky. another approach is to use 'wget' to fetch a webpage from the local server. Repeatedly invoke wget (with pauses in-between) until ERRORLEVEL indicates success.
- wget for Windows
- Testing for a specific ERRORLEVEL in batch files
- How to pause in a batch file
精彩评论