import java.io.IOException;
import java.io.InputStream;
public class Testwindow {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// window下
Runtime rt = Runtime.getRuntime();
// Process process=rt.exec("cmd /c start dir");
// 说明:&在cmd中作为关键字保留,还有空格等 你最好都转义一下 前面加^ 就行
// Process process2=rt.exec("cmd /c start http://www.sina.com");
// 在linux下
//Process process2 = rt.exec("gedit");
Process process2 = rt.exec("ls /");
InputStream is=process2.getInputStream();
int i=0;
byte[] b=new byte[1024];
while((i=is.read(b))!=-1)
{
System.out.println(new String(b,0,i));
}
System.out.println(process2);
}
}