aspose file tools*
The moose likes JSP and the fly likes Problem in executing shell script using JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Problem in executing shell script using JSP" Watch "Problem in executing shell script using JSP" New topic
Author

Problem in executing shell script using JSP

Srinivas Saranu
Greenhorn

Joined: Oct 02, 2002
Posts: 7
hi
Iam facing a problem on executing a linux shell script from JSP using Tomcat server.Iam successfully able to execute to script using the following java code
import java.io.*;
class shExecute{
public static void main(String args[]){
Runtime r=Runtime.getRuntime();
Process p =null;
String cmd="/home/shdir/runmms.sh";
try{
p=r.exec(cmd);
InputStreamReader isr=new Input StreamReader(p.getInputStream());
String line=null;
while((line=br.readLine())!=null){
System.out.println(line);
}
p.waitFor();
}
catch(Exception e){System.out.println(e);}
System.out.println(p.exitValue());
}
}
If i try to run the same script using the following jsp code iam not able to run the script.The following is the JSP code
<%@page import="java.io.*"%>
<%
Runtime r=Runtime.getRuntime();
Process p=null;
String s=null;
String cmd="/home/shdir/runmms.sh";
try{
p=r.exec(cmd);
InputStreamReader isr=new InputStreamReader(p.getInputStream());
BufferedReader br=new BufferedReader(isr);
String line=null;
while((line = br.readLine()) != null){
System.out.println(line);
}
p.waitFor();
}
catchException e){
out.println(e);
}
System.out.println(p.exitValue());
%>
can anybody give me the solution why the same java code is not working using JSP.Can there be any problem with Tomact?
Thanks to all in advance
[ October 29, 2002: Message edited by: Srinivas Saranu ]
Rajesh Kumaresan
Greenhorn

Joined: Jun 24, 2013
Posts: 12
me too the same problem , anybody help please

thanks
Rajesh
Rajesh Kumaresan
Greenhorn

Joined: Jun 24, 2013
Posts: 12
hi
Iam facing a problem on executing a linux shell script from JSP using Tomcat server.Iam successfully able to execute to script using the following java code
import java.io.*;
class shExecute{
public static void main(String args[]){
Runtime r=Runtime.getRuntime();
Process p =null;
String cmd="/home/shdir/runmms.sh";
try{
p=r.exec(cmd);
InputStreamReader isr=new Input StreamReader(p.getInputStream());
BufferedReader br=new BufferedReader(isr);
String line=null;
while((line=br.readLine())!=null){
System.out.println(line);
}
p.waitFor();
}
catch(Exception e){System.out.println(e);}
System.out.println(p.exitValue());
}
}
If i try to run the same script using the following jsp code iam not able to run the script.The following is the JSP code and also the shell script is invoked but doesnot getting the output.......
<%@page import="java.io.*"%>
<%
Runtime r=Runtime.getRuntime();
Process p=null;
String s=null;
String cmd="/home/shdir/runmms.sh";
try{
p=r.exec(cmd);
InputStreamReader isr=new InputStreamReader(p.getInputStream());
BufferedReader br=new BufferedReader(isr);
String line=null;
while((line = br.readLine()) != null){
System.out.println(line);
}
p.waitFor();
}
catchException e){
out.println(e);
}
System.out.println(p.exitValue());
%>
can anybody give me the solution why the same java code is not working using JSP.Can there be any problem with Tomact?
Thanks to all in advance



thanks,
Rajesh
Fred Breton
Greenhorn

Joined: Oct 02, 2013
Posts: 1
replace System.out.println with just out.println and it will work ;-)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem in executing shell script using JSP