目标:我试图在exec
命令中使用 2 个字符串 var 作为 shell 脚本的参数。
字符串从 HTML 前端很好地传递,但 exec 不允许它们在 exec 字符串中。
我错过了什么?
<%@page import="java.io.*"%>
<%@page import="java.util.*"%>
<html>
<head>
<title> Test</title>
<head/>
<body>
<%
String username, password;
if(request.getParameter("txtUserName") == null)
username = "";
else
username = request.getParameter("txtUserName");
if(request.getParameter("txtPassword") == null)
password = "";
else
password = request.getParameter("txtPassword");
Runtime r = Runtime.getRuntime();
Process p = null;
String s = null;
String cmd = "/tools/scripts/jspTest.sh";
p = r.exec(cmd + username + password);
InputStreamReader isr = new InputStreamReader(p.getInputStream());
BufferedReader br = new BufferedReader(isr);
String line = null;
while((line = br.readLine()) != null){
out.println(line);
}
p.waitFor();
%>