package com.travelsky.jcf;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class SystemUtils {
public static void main(String[] args) {
SystemUtils.getPID();
}
private static String getPID() {
String pid = null;
String cmd = "tasklist";
try {
Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec(cmd);
BufferedReader br = new BufferedReader(new InputStreamReader(
process.getInputStream()));
String line = null;
while ((line = br.readLine()) != null) {
if (line.indexOf("javaw") != -1) {
System.out.println(line.split(" +")[1]);
System.out.println(line);
}
}
} catch (IOException e) {
e.printStackTrace();
}
return pid;
}
}
Java获取processId
最新推荐文章于 2023-05-05 17:34:11 发布