R
Robin Clarke
Hi all,
I am having trouble getting a response from the Runtime.exec()
command. I am simply trying to execute a "df -k" command and display
the output on a JSP (see below). When I run the page in Windows it
works, when I run it in AIX it fails.
I am using WebSphere 4.0.4 on AIX 5.1 (JDK 1.3.1).
When I hit the page I see that a second java process is started (by
doing a ps -ef from the command line), with the same parameters as the
App Server that the page is in. When I load the JSP in IE, the page
takes for ever to load. It does not time out or return an error.
The code seems to hang when I try to read from the buffer - see my
System.outs below.
Does anyone have any ideas?
Thanks
robin
I copied this code from -
http://developer.java.sun.com/developer/TechTips/2000/tt0209.html#tip2
Start of diskspace.jsp
------------------------------
<%@ page import="java.io.*"%>
<%@ page import="java.util.*"%>
<%
String[] cmd = new String[3];
// Windows - works fine.
// cmd[0] = "cmd.exe" ;
// cmd[1] = "/C" ;
// cmd[2] = "dir";
// AIX - does not work
cmd[0] = "/bin/sh";
cmd[1] = "-c";
cmd[2] = "/usr/bin/df -k";
// set up list to capture command output lines
ArrayList list = new ArrayList();
// start command running
Process proc = Runtime.getRuntime().exec(cmd);
// get command's output stream and
// put a buffered reader input stream on it
InputStream istr = proc.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(istr));
// read output lines from command
System.out.println("gets here.");
String str;
while ((str = br.readLine()) != null) {
list.add(str);
System.out.println("DOES NOT get here.");
}
System.out.println("DOES NOT get here.");
// wait for command to terminate
try {
proc.waitFor();
}
catch (InterruptedException e) {
System.err.println("process was interrupted");
}
// check its exit value
if (proc.exitValue() != 0)
System.err.println("exit value was non-zero");
// close stream
br.close();
%>
<html>
<head>
</head>
<body>
<%
for (int i = 1; i < list.size(); i++) {
%>
<%=(String) list.get(i)%>
<%
}
%>
</body>
</html>
I am having trouble getting a response from the Runtime.exec()
command. I am simply trying to execute a "df -k" command and display
the output on a JSP (see below). When I run the page in Windows it
works, when I run it in AIX it fails.
I am using WebSphere 4.0.4 on AIX 5.1 (JDK 1.3.1).
When I hit the page I see that a second java process is started (by
doing a ps -ef from the command line), with the same parameters as the
App Server that the page is in. When I load the JSP in IE, the page
takes for ever to load. It does not time out or return an error.
The code seems to hang when I try to read from the buffer - see my
System.outs below.
Does anyone have any ideas?
Thanks
robin
I copied this code from -
http://developer.java.sun.com/developer/TechTips/2000/tt0209.html#tip2
Start of diskspace.jsp
------------------------------
<%@ page import="java.io.*"%>
<%@ page import="java.util.*"%>
<%
String[] cmd = new String[3];
// Windows - works fine.
// cmd[0] = "cmd.exe" ;
// cmd[1] = "/C" ;
// cmd[2] = "dir";
// AIX - does not work
cmd[0] = "/bin/sh";
cmd[1] = "-c";
cmd[2] = "/usr/bin/df -k";
// set up list to capture command output lines
ArrayList list = new ArrayList();
// start command running
Process proc = Runtime.getRuntime().exec(cmd);
// get command's output stream and
// put a buffered reader input stream on it
InputStream istr = proc.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(istr));
// read output lines from command
System.out.println("gets here.");
String str;
while ((str = br.readLine()) != null) {
list.add(str);
System.out.println("DOES NOT get here.");
}
System.out.println("DOES NOT get here.");
// wait for command to terminate
try {
proc.waitFor();
}
catch (InterruptedException e) {
System.err.println("process was interrupted");
}
// check its exit value
if (proc.exitValue() != 0)
System.err.println("exit value was non-zero");
// close stream
br.close();
%>
<html>
<head>
</head>
<body>
<%
for (int i = 1; i < list.size(); i++) {
%>
<%=(String) list.get(i)%>
<%
}
%>
</body>
</html>