Need to execute wrapper script from webapp and display console output on page

I'm looking for Java examples or a library to help me integrate this into a Struts2 / Spring application. Many build systems like Luntbuild or Hudson have this functionality, I thought I'd ask if anyone knows of a separate example before I try to dig it out of one of them. I also looked at the Quartz work scheduling framework but haven't found any user interfaces yet. Do I just need to read from a file with a JSP?

0


source to share


1 answer


If I understand what you are trying to do, this is one way in Java. This runs the ls command and then grabs the shell output and writes it back to System.out.



public class TestShell {
    public static void main(String[] args)
    {
        try
        {
                String cmd = "ls\n";
                Process p = Runtime.getRuntime().exec(cmd);
                p.waitFor();
                BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
                while(r.ready()) {
                    System.out.println(r.readLine());
                }

        }
        catch (Throwable t)
                {
                t.printStackTrace();
        }
    }
}

      

+2


source







All Articles