请给出正解,谢谢!!

解决方案 »

  1.   

    // 仅供参照
    import java.io.InputStream;
    import java.io.BufferedInputStream;
    import java.io.IOException;public class Test {    static public void main(String[] args) {
            String cmd = "ping 127.0.0.1";        try {
                Process ps = Runtime.getRuntime().exec(cmd);
                System.out.print(loadStream(ps.getInputStream()));
                System.err.print(loadStream(ps.getErrorStream()));
            } catch(IOException ioe) {
                ioe.printStackTrace();
            }
        }    // read an input-stream into a String
        static String loadStream(InputStream in) throws IOException {
            int ptr = 0;
            in = new BufferedInputStream(in);
            StringBuffer buffer = new StringBuffer();
            while( (ptr = in.read()) != -1 ) {
                buffer.append((char)ptr);
            }
            return buffer.toString();
        }
    }
      

  2.   

    bat可以直接运行的,不用上面那么麻烦,下面是个执行tomcat的例子,返回了可能的出错信息,不然大部分代码都可去掉,转的,我已经试验过,可行    public Hello() throws IOException
        {
             System.out.println("startup...");
        }
        // startup
        public static void main(String args[])
        {
             try{
                Process p =  Runtime.getRuntime().exec("C:\\Tomcat5.0\\bin\\startup.bat");
                DataInputStream ls_in = new DataInputStream(p.getInputStream());
                String ls_str;                   try {
             while ((ls_str = ls_in.readLine()) != null) {
               System.out.println(ls_str);
             }
           } catch (IOException e) {
             System.exit(0);
           }
             }
             catch(Exception ex)
             {
                  System.out.println("startup Exception: " + ex);
             }
        }
      

  3.   

    exec()
    里面的参数是需要绝对路径的