Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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 ;-)
 
 
subject: Problem in executing shell script using JSP
 
Similar Threads
Why is Runtime.getRuntime().exec() not working in JSP?
Executing a UNIX shell script using JAVA
runnning a shell script from mac os x
Problem with running a shell script from the JSP
how to execute shell(unix) through a servlet.