PDA

View Full Version : Unable to run an exe file from a Servlet


Bijumon
08-12-2008, 02:45 AM
I am not able to run a Servlet that calls an exe file using the follwing code. trial.exe is was built from a C program and it is simply a program that creates a text file with some content. I am using Tomcat 6.0 and JDK 1.5 on a Windows XP.





try
{
Runtime rt=Runtime.getRuntime();
String[] command = {"C://Tomcat 6.0//webapps//ROOT//WEB-INF//classes//trial.exe"};


Process p = Runtime.getRuntime().exec(command);
p.waitFor();

}
catch(Throwable t)
{
// System.out.print(t.getMessage());

}


Before running the code on Tomcat I've compiled the code above in a simple java programe and it executed without any problem.


Then I compiled the code within a servlet. No luck. Then I treid the following options:

Executed the Tomcat service under the context of a user by specifying a user(Log On option) for the Tomcat service.

Then with Local System Account, selecting “Allow service to interact with desktop”.

this time also, no luck. Can somebody help me on this please BJJ?

shyam
08-16-2008, 06:54 PM
try
{
Runtime rt=Runtime.getRuntime();
String[] command = {"C://Tomcat 6.0//webapps//ROOT//WEB-INF//classes//trial.exe"};


Process p = Runtime.getRuntime().exec(command);
p.waitFor();

}
catch(Throwable t)
{
// System.out.print(t.getMessage());

}

what is the exception that is thrown?
plus you need to escape backslashes only \\ forward slashes need not be escaped / so, probably you are getting a file/resource not found exception...
String[] command = {"C:/Tomcat 6.0/webapps/ROOT/WEB-INF/classes/trial.exe"};

servlet
05-12-2009, 09:06 AM
I have put one simple and running example on the same here

http://************************/2009/05/how-to-use-runtimegetruntimeexec-how-to.html

Thanks,

Binod Suman
http://*************************

Don't bump threads just to put links to your blog.
The question is 10 months old, he is not gonna read your answer,
Being an architect (As said in your blog) you should have this common sense.

I hope, you will take it seriously.

Reporting to Mod