1 Reply Latest reply on Feb 26, 2013 7:17 AM by EJP

    How to Execute a Linux Command in JSP

    Stanley Lee-Oracle

      I would like to run 'whoami' in my jsp. It only works when I put in the absolute path '/usr/bin/whoami'.

      Is there a way to import the path without changing my code? Thanks.


      String cmd = "/usr/bin/whoami"; // I would like to leave it as "whoami" without the path
      process = rt.exec(cmd);

      BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
      out.print("<BR>" + cmd +"<BR>");

      while ((line = reader.readLine()) != null) {
      out.print( line);