How to call Unix Shell Script from a Servlet?

Discussions

Web tier: servlets, JSP, Web frameworks: How to call Unix Shell Script from a Servlet?

  1. How to call Unix Shell Script from a Servlet? (2 messages)

    Hi,
    I am looking for help, to write a Servlet to call a Shell script on Unix which eventualy Start/Stop a component and taking status back to browser.

    Thanks in Advance
    Devendra
  2. Check the following code stub on java.sun.com
    Developer connection.
     
    try {
    // Execute command
    String command = "ls";
    Process child =
    Runtime.getRuntime().exec(command);
    // Get input stream to read from it
    InputStream in = child.getInputStream();
    int c;
    while ((c = in.read()) != -1) {
    process((char)c);
    }
    in.close();
    } catch (IOException e) {
    }
  3. Thanks a lot!!