public static boolean isStarted(){
boolean flag = true;
String com1 = " cmd.exe /c tasklist |find ";
String com2 = "\"1.exe\"" ;
String command = com1 + com2;
try {
Process ps = Runtime.getRuntime().exec(command);
BufferedReader reader = new BufferedReader(new InputStreamReader(ps.getInputStream()));
String str = reader.readLine();
if(str != null){
flag = true;
}else{
flag = false;
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("111111" + command + "------" + flag);
return flag;
}
boolean flag = true;
String com1 = " cmd.exe /c tasklist |find ";
String com2 = "\"1.exe\"" ;
String command = com1 + com2;
try {
Process ps = Runtime.getRuntime().exec(command);
BufferedReader reader = new BufferedReader(new InputStreamReader(ps.getInputStream()));
String str = reader.readLine();
if(str != null){
flag = true;
}else{
flag = false;
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("111111" + command + "------" + flag);
return flag;
}
本文介绍了一个简单的Java方法用于检查名为“1.exe”的进程是否正在运行。通过构建命令并使用Runtime.getRuntime().exec()来执行该命令,可以获取当前系统中运行的任务列表,并进一步判断指定进程是否存在。文章提供了一个具体的实现示例。
5215

被折叠的 条评论
为什么被折叠?



