jsp 調用linux shell

<%@ page language="java" import="java.io.*" pageEncoding="UTF-8"%>

<%

String path = request.getContextPath();

String basePath = request.getScheme() + "://"

+ request.getServerName() + ":" + request.getServerPort()

+ path + "/";

 

%>

<html>

<head>

<title>shell</title>

</head>

<body>

<%

String cmds = "monitor.sh";

try {

 

        Process process;  

        process = Runtime.getRuntime().exec("sh /opt/wzx/monitor.sh");  

        InputStreamReader ir = new InputStreamReader(process  

                .getInputStream());  

        LineNumberReader input = new LineNumberReader(ir);  

        String line;  

        process.waitFor();  

        while ((line = input.readLine()) != null){  

         out.print(line);

out.print("<br/>");

        }  

         if(input!=null){

input.close();

}

 

} catch (Exception e) {

e.printStackTrace();

}

 

%>

 

</body>

</html>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章