Launching a cmd window from within a servlet
Hi,
Im trying to launch a program from a servlet. Im using the following code:
try{
log.debug("Starting the cruisecontrol batch file...");
//a batch file on the path to start cc
Runtime.getRuntime().exec("rundll32 SHELL32.DLL,ShellExec_RunDLL c:/tools/startcruisecontrol.bat");
log.debug("Should have started...");
}
catch(Exception ex){
log.error("Exception thrown: "+ex.getMessage());
}
This should just launch a cmd window and work away like that and I can forget about it.
In testing this is fine. Im developing it for tomcat and it works fine running on tomcat from within eclipse but when i load it into a standalone tomcat, this fails to work. Im really stumped on this as it works fine in eclipse. Any ideas Id be very appreciative.
Thanks
# 3
There is a security sandbox that the server JVM is run on to prevent bad things from happening. The eclipse adds permissions (actually removes all the security parameters) so the sandbox doesn't get in the way. This is controlled via startup flags for the java.exe executable, and for the tomcat.exe executable. I don't recall them off the top of my head, but you should be able to look them up either in the java or tomcat configuration manuals.
# 4
Hi, thanks for that response. I was reading about this on the Tomcat site. Am I right in saying that permissions will be controlled from the Catalina.policy file? It says on their website:
"If your web application attempts to execute an operation that is prohibited by lack of a required Permission, it will throw an AccessControLException or a SecurityException when the SecurityManager detects the violation."
My code is not throwing any exceptions though. It is just failing to execute.
Message was edited by:
niceguyeddie82
# 5
Hey,
I got it working, but I dont know why :-) It doesnt work when I start tomcat like this
tomcat5.exe start
But when I use
tomcat5.exe start -security
it does. When I use -security my understanding is that it enforces catalina.policy. I guess what I want to know is what are the security enforcements when I dont use -security?