my dog learned polymorphism*
The moose likes Java in General and the fly likes exec command not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "exec command not working" Watch "exec command not working" New topic
Author

exec command not working

govind bhardwaj
Greenhorn

Joined: Sep 17, 2010
Posts: 2
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.

Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 9990
    
    7

Welcome to the Ranch.

In future, while posting code, please UseCodeTags


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36514
    
  16
Where does it return null? There aren't any return statements in what you posted.
govind bhardwaj
Greenhorn

Joined: Sep 17, 2010
Posts: 2
the thing inside the while loop doesn't seem to work.
So i wrote down

String answer;
answer=buf.readLine();
out.write(command+answer);

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: 12682
    
    5
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."

Bill

Java Resources at www.wbrogden.com
Guido Granobles
Greenhorn

Joined: Sep 11, 2010
Posts: 22
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


http://guido-granobles.blogspot.com
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

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://aspose.com/file-tools
 
subject: exec command not working
 
Similar Threads
FILE NOT READING IS JSP
Error printing out from a read in file.
a file in your Jar, How do I access it in code?
Executing Unix Command Through Java
Executing a *.bat file