问题
I would like to know if there is any way of running an operation (like, calling a batch file) before a service is started using services.msc?
I want my batch file to run before the service (tomcat installed as service) is actually started, when the user manually clicks 'Start' in Services.
I don't know if this is possible or not. Thank you for your help in advance!
回答1:
The answer to your question is NO, unless you want to modify Apache's procrun
(which is written in C language).
Depending on what you wanted to do, you should also check my answer here.
One possible way of doing something when a web application is started - on top my mind - would be to write a javax.Servlet.ServletContextListener
as explained here. In
you listener's contextInitialized()
you would start your BAT file via Runtime.exec()
as explained here.
来源:https://stackoverflow.com/questions/9255003/running-a-batch-file-before-tomcat-service-starts-when-user-manually-starts-the