This discussion is archived
1 Reply Latest reply: Feb 25, 2013 11:17 PM by EJP RSS

How to Execute a Linux Command in JSP

Stanley Lee-Oracle Newbie
Currently Being Moderated
Hi,

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.

Example:


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);
out.print("<BR>");

}

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points