前段时间测试的时候发现客户端,双击图标多次回生成多次XXX.exe.所以在启动时判断一下时候有进程已经启动了,下面把代码写出来。
public boolean getProcess(){
boolean flag=false;
try{
Process p = Runtime.getRuntime().exec( "cmd /c tasklist ");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
InputStream os = p.getInputStream();
byte b[] = new byte[256];
while(os.read(b)> 0)
baos.write(b);
String s = baos.toString();
// System.out.println(s);
if(s.indexOf( "Besttone.exe ")>=0){
System.out.println( "yes ");
flag=true;
}
else{
System.out.println( "no ");
flag=false;
}
}catch(java.io.IOException ioe){
}
return flag;
}
查看进程中是否包含 ie 或者 ff的进程
Process p = Runtime.getRuntime().exec("tasklist ");
System.out.println(p);
BufferedReader bw = new BufferedReader(new InputStreamReader(p
.getInputStream()));
String str = "";
StringBuffer sb = new StringBuffer();
while (true) {
str = bw.readLine();
if (str != null) {
sb.append(str.toLowerCase());
} else {
break;
}
}
String ff = "firefox.exe";
String ie = "iexplore.exe";
if (sb.toString().indexOf(ff) != -1) {
System.out.println("ff 已经启动!");
}
if (sb.toString().indexOf(ie) != -1) {
System.out.println("ie 已经启动!");
}

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



