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

[1134 byte] By [869065niceguyeddie82a] at [2007-11-26 12:18:09]
# 1
The servlet code runs on the server which means the Runtime.getRuntime().exec() command will be executed on the server and if a cmd windows opens it will be on the server. If you want to run the command on the client machine you'll have to use a Java Applet and sign the applet.
228598tolmanka at 2007-7-7 14:57:20 > top of Java-index,Archived Forums,Socket Programming...
# 2

Hi,

Thanks for your response. Thats what I want to happen though. Its a remote interface to start this program running on that server. Im testing on my localhost and when that code is hit in the standalone tomcat, nothing happens. Yet when I step through in Eclipse (Im using the Sysdeo plugin) it starts up the program in a seperate cmd window as expected.

869065niceguyeddie82a at 2007-7-7 14:57:20 > top of Java-index,Archived Forums,Socket Programming...
# 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.

282956stevejlukea at 2007-7-7 14:57:20 > top of Java-index,Archived Forums,Socket Programming...
# 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

869065niceguyeddie82a at 2007-7-7 14:57:20 > top of Java-index,Archived Forums,Socket Programming...
# 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?

869065niceguyeddie82a at 2007-7-7 14:57:20 > top of Java-index,Archived Forums,Socket Programming...