会计考友 发表于 2012-8-4 12:37:27

JAVA基础:java如何判断某个进程是否在启用

前段时刻测试的时辰发现客户端,双击停笔多次回生成多次XXX.exe.所以在启动时判定一下时辰有历程已经启动了,下面把代码写出来。
  Java代码
  publicboolean 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;
  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;
  }
页: [1]
查看完整版本: JAVA基础:java如何判断某个进程是否在启用