该代码列出 Windows 下当前运行的所有进程
import java.io.*; public class ListProcess { public static void main(String[] args) throws IOException { Runtime runtime = Runtime.getRuntime(); String cmds[] = {"cmd", "/c", "tasklist"}; Process proc = runtime.exec(cmds); InputStream inputstream = proc.getInputStream(); InputStreamReader inputstreamreader = new InputStreamReader(inputstream); BufferedReader bufferedreader = new BufferedReader(inputstreamreader); String line; while ((line = bufferedreader.readLine()) != null) { System.out.println(line); } } }
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/10810.html