import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
public class Test {
class ExeCom extends Thread {
InputStream is;
ExeCom(InputStream is) {
this.is = is;
}
public void run() {
try {
System.out.println("New thread start, sleep 500ms...");
Thread.currentThread().sleep(500);
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line = null;
while ((line = br.readLine()) != null) {
System.err.println(line);
}
} catch (Exception ioe) {
ioe.printStackTrace();
}
}
}
public void oper(){
try {
Process process=Runtime.getRuntime().exec("ls");
new ExeCom(process.getInputStream()).start();
process.waitFor();
System.out.println("Main thread wait for");
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args){
Test t= new Test();
t.oper();
}
}
Java执行Linux命令
最新推荐文章于 2025-02-27 22:20:43 发布
