public class TestCmd {
  public TestCmd(){}
  public static void main(String args[]){
        try {
        Process process = Runtime.getRuntime().exec("cmd.exe  /c start http://www.csdn.net");     
        }catch (Exception  e)
        {
            e.printStackTrace();
            }  
        
      }
    }  
}

解决方案 »

  1.   

    你把http://www.csdn.net改成http://www.sina.com.cn就行了
      

  2.   

    最近怎么老是看到有人把Runtime.getRuntime().exec()写成Runtime.getRuntime().exce()啊。
      

  3.   

    不知道getInputStream会不会返回那些字符,你试试看
      

  4.   

    to narilee(Unchecked Exception,Don't Catch Me!) 用你的方法的确返回了process,但怎么样操作process才能把内容得到呢?用process.getInputStream
      

  5.   

    http://www.rgagnon.com/javadetails/java-0014.htmlCapture the output of JAVAC
    method 1a : redirect to a file    // Win95 (?)
       javac -J-Djavac.pipe.output=true myClass.java >output.txt
       // WinNT (or better)
       javac myClass.java 2>output.txt
     
    method 1a : redirect to stdout with a pause after each screen full    // WinNT (or better)
       javac myClass.java 2>&1 | more
     
    method 2 : use JAVA to capture the output //  [JDK 1.1]
    //  to compile:  java JC mySource.java
    //       (use redirection to keep the output)
    //               java JC mySource.java >output.txtimport java.io.*;
    public class JC {
      public static void main( String args[] )
         throws IOException, InterruptedException {
        String fn = "JC.java";
        if( args.length > 0 ) fn = args[0];
        System.out.println( "BEGIN (" + fn + ")" );
        Process p = 
            Runtime.getRuntime().exec( "javac -verbose " + fn );
        String buf;
        BufferedReader se = new BufferedReader
            ( new InputStreamReader( p.getErrorStream() ) );
        while( (buf = se.readLine()) != null ) 
           System.out.println( " : " + buf );
        System.out.println( "END (rc:" + p.waitFor() + ")" );
        }
      }
     
      

  6.   

    public class ReadingProcess {

    private Process process = null;
    private BufferedReader buffIn = null ;
    private String message = null ;
    private List msgList = null ;

    public List doProcess(String pProcess){
    Runtime runtime = Runtime.getRuntime();
    msgList = new ArrayList(); try {
    process = runtime.exec(pProcess);
    buffIn = new BufferedReader( new InputStreamReader( process.getInputStream()));
    while((message=buffIn.readLine())!=null){
    msgList.add(message);
    }
    buffIn.close();
    } catch (IOException e) {
    e.printStackTrace();
    }
    return msgList;
    }
    }public class MainProc {    public static void main(String[] args) { ReadingProcess rp = new ReadingProcess();
             List list = rp.doProcess("cmd.exe /c dir");
        }
    }以前写的一个类,用来读取process返回信息用的,因为返回信息可能是多行,所以放在一个list中