File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Runtime.getRuntime().exec() from JSP page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Runtime.getRuntime().exec() from JSP page" Watch "Runtime.getRuntime().exec() from JSP page" New topic
Author

Runtime.getRuntime().exec() from JSP page

Manimekala Velautham
Greenhorn

Joined: May 31, 2006
Posts: 16
I have a jsp page, there I want to execute the following shell script with the exit codes for 0 and 1 for success and fail respectively thru Runtime.getRuntime().exec().



The exection is success while execting the shell script alone and also thru a stand alone Java program. But While calling this shell script from the JSP, I am always getting the negative response, that is the Process.exitValue() returns always 1.

Any suggestions and help appreciated !!!
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12678
    
    5
if [ -f "help.txt" ]


That would appear to depend on the "current" directory. You have no control over the current directory in the servlet environment.

Bill


Java Resources at www.wbrogden.com
Preeti Arora
Ranch Hand

Joined: Jan 26, 2007
Posts: 74
Hi,

Thats how I have done.I am running an exe file to convert dms to tiff.I have used absolute path.


Hope this will hepl


[BSouther: Added UBB CODE tags]
[ April 24, 2007: Message edited by: Ben Souther ]
Preeti Arora
Ranch Hand

Joined: Jan 26, 2007
Posts: 74
Hi,

Thats how I have done.I am running an exe file to convert dms to tiff.I have used absolute path.

String[] cmd = { "C:\\imaging\\kman_DMStoTiff\\bin\\kman_DMStoTiff.exe", "C:\\imaging\\test.dms", "C:\\jboss-4.0.5.GA\\server\\default\\deploy\\documents.war\\pal1.tiff" } ;
Process p = Runtime.getRuntime().exec(cmd) ;
BufferedReader in =new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
System.out.println(line);
}
p.destroy();

Hope this will help
Manimekala Velautham
Greenhorn

Joined: May 31, 2006
Posts: 16
Yeah...I forgot to think this way...this fixed my problem and is working fine. Thanks
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Runtime.getRuntime().exec() from JSP page
 
Similar Threads
about Runtime.getRuntime().exec(shellCmd) create process
aboue Runtime.getRuntime().exec() create process
Capturing error codes from a shell script -Urgent!
Problem running unix script through servlet
How to return a string number from shell script?