主要使用Runtime和Process兩個類
package shelltest;
import java
import java
import java
import java
import java
import java
import java
/**
*
* @author Wei
*/
public class Shell {
private Process pro = null;
private Runtime runTime = null;
public Shell() {
runTime = Runtime
if (runTime == null) {
System
System
}
}
public void execueteCommand(String command) throws InterruptedException {
System
System
System
try {
pro = runTime
BufferedReader input = new BufferedReader(new InputStreamReader(pro
PrintWriter output= new PrintWriter(new OutputStreamWriter(pro
String line;
while ((line = input
System
if(
output
output
}
}
System
input
output
pro
} catch (IOException ex) {
Logger
}
}
}
From:http://tw.wingwit.com/Article/program/Java/hx/201311/27038.html