The following code was working fine in a separate program, but when I inserted into my Servlet code, it always returns a null. Can anyone please tell where am I going wrong.
and what i at the other end was
"java add 2 3null"
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12265
1
posted
0
If the process failed at the start and only wrote to the stderr stream, then you would get null from the buf.readLine()
Does the Java program you are attempting to run have some assumption about the "current directory"? Remember, in the servlet environment you have no control over the "current directory."
If you are using Tomcat as a servlet container then the Java classes that you want execute should be in the ROOT directory. That is to say in something like $TOMCA_HOME/webapps/yourWebApp/ROOT. If your classes are packaged then you should have the directory in there: ROOT/namePackage1/myClass
It may not completely apply to this topic however this is a good article about using Runtime.exec().
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.