java jsp調用shell(帶參數)腳本並返回值


test.jsp

<%@ page language="java" import="java.util.List,java.util.ArrayList,java.io.InputStreamReader,java.io.BufferedReader" pageEncoding="utf-8"%>
<%
 List<String> processList = new ArrayList<String>(); 
 String str="";
        try { 

  //11 aa為參數用空格隔開,也可以不帶參數,與前面腳本用空格隔開,腳本帶上絕對路徑
         Process process = Runtime.getRuntime().exec("sh /usr/local/jboss5/server/default/deploy/sanguo_root.war/test.sh 11 aa");
         int exitValue = process.waitFor();
         //out.print(exitValue);腳本正確執行返回值為0
         if(0!=exitValue)
          process.destroy();
            BufferedReader input = new BufferedReader(new InputStreamReader(process.getInputStream())); 
            String line = ""; 
            while ((line = input.readLine()) != null) { 
                processList.add(line); 
            } 
            input.close(); 
        } catch (Exception e) { 
            e.printStackTrace(); 
        } 
 
        for (String line : processList) {
          str+=line;
          
        } 
        out.print(str+"");
%>

java技術交流群57388149

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM