import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
/**
* @version 创建时间:2020年11月6日 上午11:15:36
*/
public class ProcessList {
public static void main(String[] args) throws IOException {
// 创建系统进程
ProcessBuilder pb = new ProcessBuilder("tasklist");
Process p = pb.start();
BufferedReader out = new BufferedReader(new InputStreamReader(new BufferedInputStream(p.getInputStream()), Charset.forName("GB2312")));
BufferedReader err = new BufferedReader(new InputStreamReader(new BufferedInputStream(p.getErrorStream())));
System.out.println("Window 系统进程列表");
String ostr;
while ((ostr = out.readLine()) != null)
System.err.println(ostr);
String estr = err.readLine();
if (estr != null) {
System.out.println("\nError Info");
System.err.println(estr);
}
}
}
运行结果: