| Author |
Running an exe in tomcat
|
ajse ruku
Ranch Hand
Joined: May 06, 2005
Posts: 192
|
|
Hi all, I am facing a strange problem.If i run an exe program simply through a java class ,writing the following code inside the main method Runtime r=Runtime.getRuntime(); Process p=r.exec("C:/dir/com"); //where com is the name of the exe. the exe is running fine.But the same code if i write in an action class(struts) (tomcat web server ),the exe is starting but getting stopped immediately.What could be reason for this?Does tomcat has any restriction or the exe is taking too much resource,that is why tomcat is stopping this or anything else?Please express your views, with regards, ajse with regards, ajse
|
 |
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12265
|
|
getting stopped immediately.
What exactly happens? I assume you have provided for consuming the output from the process - is any produced? Is Tomcat being started with the -security option? Bill
|
Java Resources at www.wbrogden.com
|
 |
ajse ruku
Ranch Hand
Joined: May 06, 2005
Posts: 192
|
|
Hi all, When I try to run an exe in my action class(struts,Tomcat 5.o),I get java.security.AccessControlException access denied(java.io.FilePermission).How to solve this problem?Please express your views. with regards, Ajse
|
 |
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12265
|
|
Exactly where is this exception thrown? If it is thrown at the point exec() is called that should be a clue. You still have not answered my question:
Is Tomcat being started with the -security option?
I suspect the answer is yes - in which case you need to read the Tomcat docs "security-manager-howto.html" in a typical Tomcat installation. Bill
|
 |
ajse ruku
Ranch Hand
Joined: May 06, 2005
Posts: 192
|
|
Hi William, Thanks for yuor message.If I am starting tomcat with security option ,then I am getting the exception when i am calling exec. If i start tomcat without security option,then no exception is coming and exe is starting and stopped immediately. with regards, ajse
|
 |
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12265
|
|
Assuming you have read the Tomcat security manager docs, lets move on to this exe that stops immediately. Have you provided for grabbing the output of the process that is started and logging it. Note that you will need to get both standard out and standard error output streams. Does this exe have any dependence on the "current" directory? Where does the normal output go? Bill
|
 |
ajse ruku
Ranch Hand
Joined: May 06, 2005
Posts: 192
|
|
Hi William, I have tried to read the error and inputstream of the process,but nothing is coming from that.The exe also does not depend on the current directory. If I am writing my exec command in an infinite loop,then several instances of the exe are starting but getting stopped immediately.From this we can conclude that the exe is starting but not continuing. with regards, ajse
|
 |
ajse ruku
Ranch Hand
Joined: May 06, 2005
Posts: 192
|
|
Hi William, You are correct.The exe needs to be placed at %TOMCAT_HOME%/bin,because that is the current directory when tomcat is running.The exe is running fine if it is in %TOMCAT_HOME%/bin. But my problem is that,I cannnot place the exe at %TOMCAT_HOME%/bin.I have tried to change the current directory by System.setProperty("C:/prog") but the exe is not running now.But System.getProperty("user.dir") is showing C:/prog. What should I do? with regards, ajse
|
 |
Ben Souther
Sheriff
Joined: Dec 11, 2004
Posts: 13410
|
|
|
Why not put the exe file where you want it and call it with an absolute path?
|
Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
|
 |
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12265
|
|
What Ben said! There are many different ways of setting up exec() calls - there is even one designed to let you specify the "working directory" the process will use. Go hit the books (ie, the Javadocs for java.lang.Runtime exec() )
because that is the current directory when tomcat is running.
Nobody should ever depend on that remaining true, that is an accident of the way you are starting Tomcat. Bill
|
 |
 |
|
|
subject: Running an exe in tomcat
|
|
|