aspose file tools*
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


Win a copy of Spring in Action this week in the Spring forum!
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: 10451
    
    8

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: 39396
    
  28
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: 12803
    
    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
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