62,621
社区成员
发帖
与我相关
我的任务
分享/**
*
*/
package pkg;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
/**
* @author 2172980000502
*
*/
public class TestProcess {
/**
* @param args
*/
public static void main(String[] args) {
try {
Process exec = Runtime.getRuntime().exec("cmd");
InputStream inputStream = exec.getInputStream();
OutputStream outputStream = exec.getOutputStream();
outputStream.write("dir\r\n".getBytes());
int c;
while ((c = inputStream.read())!=-1) {
System.out.print((char)c);
}
System.out.println("end");
} catch (IOException e) {
e.printStackTrace();
}
}
}
try {
Process proc = Runtime.getRuntime().exec("ping www.baidu.com");
InputStream inputStream = proc.getInputStream();
String line = "";
BufferedReader buf = null;
buf = new BufferedReader(new InputStreamReader(inputStream));
while ((line = buf.readLine()) != null){
System.out.println(line);
}
System.out.println("end");
} catch (IOException e) {
e.printStackTrace();
}