加上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();
}
}
}
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();
}
}
}
用上面的代码可以启动F盘的notepad.exe上面是在Windows平台上的方法,那么在Linux平台上面该怎样做呢?
2应该表示得就是“系统找不到指定的文件。 ”
Runtime.getRuntime().exec("java -classpath . myhelloworld"); 不好使啊。
Runtime.getRuntime().exec("/usr/local/j2sdk1.4.1_03/bin/java -classpath . /root/helloworld"); 也不好使啊。