The Artima Developer Community
Sponsored Link

Java Answers Forum
Runtime.getRuntime().exec() Help

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Jeri Sue Ponder

Posts: 1
Nickname: plainj
Registered: Aug, 2007

Runtime.getRuntime().exec() Help Posted: Aug 10, 2007 2:00 PM
Reply to this message Reply
Advertisement
I'm trying to run a c shell script from a jsp page using Runtime.getRuntime().exec(). I can get simple unix commands to work with the code, but once I try to run a c shell script it doesn't work. I get a return code of 1. The c shell script writes a file that the jsp page then reads in, so I'm not trying to get anything other than verify the script completed. The c shell scripts runs without any errors when executed from the unix prompt. Any suggestions are welcome.

Environment info:
OS: Sun Unix
Web setup: Apache Tomcat
Java:
java version "1.5.0_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
Java HotSpot(TM) Server VM (build 1.5.0_06-b05, mixed mode)


Note:
I've already reviewed the info from: http://www.artima.com/forums/flat.jsp?forum=1&thread=115299&start=15&msRange=15
and the suggestions on it have not help me.

Here is my code
<%!
public String run(String[] cmd) {
  try {
    Runtime rt = Runtime.getRuntime();
    Process p = rt.exec(cmd);
    // Input String Info
    InputStreamReader in = new InputStreamReader(p.getInputStream());
    BufferedReader reader = new BufferedReader(in);
    StringBuffer buf = new StringBuffer();
    String line;
    String newline = "\n";
 
    while ((line = reader.readLine()) != null) {
      buf.append(line);
      buf.append(newline);
    }
 
    int exitCode = p.waitFor();
    Integer code2 = Integer.valueOf(exitCode);
    reader.close();
    p.getInputStream().close();
    p.getOutputStream().close();
    p.getErrorStream().close();
    return code2.toString(); //buf.toString(); 
  }
  catch (Exception e) {
	e.printStackTrace();
    return (e.getMessage());
  }
}
%>
<%String []cmds = {"/bin/csh","-c","/license/scripts/flex_web_stat.csh"};
String strval = run(cmds);

Topic: Runtime.getRuntime().exec() Help Previous Topic   Next Topic Topic: Servlet to Browser

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use