加上process.wait()就可以了。
public class TestCmd {
  public TestCmd(){}
  public static void main(String args[]){
        try {
    
           Process process = Runtime.getRuntime().exec("dir c:");
           process.wait();
            }
            catch (Exception  e)
        {
            e.printStackTrace();
        }  
        
                                         }
           }  

解决方案 »

  1.   

    Process pro = Runtime.getRuntime().exec("cmd /F:ON /c start notepad.exe");
    用上面的代码可以启动F盘的notepad.exe上面是在Windows平台上的方法,那么在Linux平台上面该怎样做呢?
      

  2.   

    java我没怎么用过,不过我想是"dir c:"这个东西有问题,应该是“c:”就好了java.io.IOException: CreateProcess: dir c: error=2
    2应该表示得就是“系统找不到指定的文件。 ”
      

  3.   

    如果我想在Linux上执行一个java程序,该怎么做呢?
        Runtime.getRuntime().exec("java -classpath . myhelloworld"); 不好使啊。
        Runtime.getRuntime().exec("/usr/local/j2sdk1.4.1_03/bin/java -classpath . /root/helloworld"); 也不好使啊。
      

  4.   

    不好使不要怪共产党,现在shell里看看你的内容能执行否先
      

  5.   

    在shell里我的内容可以正确执行啊