1
目標:我試圖在exec
命令中使用2個字符串var作爲shell腳本的參數。如何將JSP var傳遞給運行時exec?
字符串從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();
%>
我沒有想到這一點。我已經更改爲'p = r.exec(cmd +「」+ username +「」+ password);'那就完成了。 – Rhys