zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    CF1454F Array Partition
    leetcode1883 准时抵达会议现场的最小跳过休息次数
    leetcode1871 跳跃游戏 VII
    leetcode1872 石子游戏VIII
    CF1355C Count Triangles
    CF1245D Shichikuji and Power Grid
    CF1368C Even Picture
    CF1368D AND, OR and square sum
    CF1395C Boboniu and Bit Operations
    SpringBoot和开发热部署
  • 原文地址:https://www.cnblogs.com/Nbge/p/3159307.html
Copyright © 2011-2022 走看看