Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem in executing shell script using JSP

 
Srinivas Saranu
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
me too the same problem , anybody help please

thanks
Rajesh
 
Rajesh Kumaresan
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
replace System.out.println with just out.println and it will work ;-)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic