• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Problem in executing shell script using JSP  RSS feed

 
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 ]
 
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
 
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 ;-)
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!