I am writting this code for a JSP page that reads from an text input and passes the variables' values to a bash file as parameters, but it seems like the bash file doesn't take variables, it only worked when I passed real values instead of variables. How to pass a variable to this bash file? Here is the code:
<%
String myArgument = "";
if (request.getParameter("submit")==null)
{
%>
<form method="POST" action="/tomcat/webapps/project/jsp/runCMD.jsp" id=form2>
<input type=text id=first value="${first}" Title="IP adress here" >
<input type="submit" value="Submit Changes" name="submit"
onClick="if(runOnSubmit()){getSomethingWithAjax('ChangeIP.jsp'+
getAllFormElementsAndMakeIntoURI(true),'',
'hereIsTheMainHeaderSpan',false,false);}">
<%
}//end if
//else if submitted
else {
request.setAttribute("myArgument", myArgument);
try {
Process p = Runtime.getRuntime().exec("/root/script.cmd myArgument );
p.waitFor();
System.out.println("Waiting for the System to reboot" + p.exitValue());
} catch (Exception e) {
System.out.println(e.getMessage());
out.println("There was an error while submitting ");
}
}//end else
%>
Note that when passing a value to the script it got executed with the code below:
Process p = Runtime.getRuntime().exec("/root/changeip.cmd 10.0.100.18");