public class Test {
public static void main(String[] args) throws IOException {
// String cmd = "kill -9 812";
String cmd = "ps -ef | grep tomcat";
Process ps = Runtime.getRuntime().exec(cmd);
load(ps.getInputStream());
}
public static void load(InputStream is) throws IOException{
int ptr = 0;
is = new BufferedInputStream(is);
StringBuffer buffer = new StringBuffer();
while((ptr = is.read()) != -1){
buffer.append((char)ptr);
}
// System.out.println(buffer.toString());
String data = buffer.toString();
// String[] str = data.split("\n");
// System.out.println("length : "+str.length+" data : "+str[0]+" -- "+str[1].split(" ")[0]);
System.out.println(data);
}
}
我也遇到这个问题了,请问该怎么解决