Runtime类其中有个方法:
Process exec(String[] cmdarray, String[] envp, File dir)
在指定环境和工作目录的独立进程中执行指定的命令和变量。
try
{
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
String tempString ="";
// 一次读入一行,直到读入null为文件结束
while ((tempString = input.readLine()) !=null) {
System.out.println( tempString);
procResult+=tempString+"\n";
}
System.out.println( procResult);
input.close();
}
catch (Exception e) {
System.out.println("Error win exec!");
}
Process p = Runtime.getRuntime().exec( "C:\\socket_server\\bin\\aa\\hello.exe",null,new File("C:\\socket_server\\bin\\aa\\"));//必须通过这种方式才可以运行可执行文件!!!!
//java通过流来读取exe在控制台(操作系统的Console)上的输出,new InputStreamReader(process.getInputStream())