I would have thought this straight forward, but it doesn’t seem the case.
Aim: I am running a shell script ArgCHeck.sh through my .jsp file. This works fine and I can see the output in my system console.
However when I try and output the line into the browser through HTML, its doesn’t seem to work.
I have tried setting the String to Static final String line = "test"; and this works to output the word test, but not the value I want which is from the other String line.
Its probably something I missed, but any help is appreciate.
<%@page import="java.io.*"%>
<%@page import="java.util.*"%>
<%!
%>
<%
Runtime r=Runtime.getRuntime();
Process p=null;
String s=null;
String cmd="/tools/scripts/ArgCheck.sh orange";
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();
System.out.println(p.exitValue());
%>
<html>
<head/>
<body>
<%
// This scriptlet generates HTML output
out.println( String.valueOf( line ));
%>
</body>
</html>
————————— Edit —————————————————–
That’s what you get when you cut and paste. I read the code and it was obvious. Time for a break.
<%@page import="java.io.*"%>
<%@page import="java.util.*"%>
<html>
<head>
<head/>
<body>
<%
Runtime r=Runtime.getRuntime();
Process p=null;
String s=null;
String cmd="/tools/scripts/ArgCheck.sh";
p=r.exec(cmd);
InputStreamReader isr=new InputStreamReader(p.getInputStream());
BufferedReader br=new BufferedReader(isr);
String line = null;
while((line = br.readLine()) != null){
out.println(line);
}
p.waitFor();
%>
</body>
</html>
Here you go.. Just Change the file path .