jsp调用shell脚本

    xiaoxiao2021-04-12  37

    一个简单的例子和注意的问题

    <%@page import="java.io.BufferedReader"%> <%@page import="java.io.InputStreamReader"%> <%@page import="java.util.List"%> <%@page import="java.util.ArrayList"%> <%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>jsp调用shell脚本</title> </head> <body> <% List<String> processList = new ArrayList<String>(); String str=""; try{ Process process = Runtime.getRuntime().exec(" sh /home/hadoop/jk/Neicun.sh ---------------------------- 这里要分清tomcat是哪个所属主,我这里是hadoop.hadoop。所以我调用的是hadoop用户下的shell脚本,不然访问会出错 ");//要注意tomcat的权限问题 int exitValue = process.waitFor(); out.println(exitValue+"<br/>"); if(0 != exitValue) process.destroy(); BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream())); String line = ""; while((line = in.readLine()) != null){ processList.add(line); } input.close(); }catch(Exception e){ e.printStackTrace(); } for(String line:processList){ str+=line+"<br/>"; } out.println(str); %> </body> </html>

    这是我遇到的问题,希望有帮助。。。

    转载请注明原文地址: https://ju.6miu.com/read-667315.html

    最新回复(0)