请问:  
用Process  p  =  Runtime.getRuntime().exec("*.exe");  
这种方法开启的进程,如何让Java程序知道这个进程是否还存在?
感谢!!!=)

解决方案 »

  1.   

    p.exitValue();
    抛异常说明进程尚未终止
      

  2.   

    效率可能不太高
    定时扫描进程 new Thread(){
    public void run(){
    while(true){
    System.out.println(1);
    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("SQLyog.exe")>=0)
    System.out.println("yes");
    else
    System.out.println("no");
    Thread.sleep(1000);
    }catch(InterruptedException ie){

    }catch(java.io.IOException ioe){

    }
    }
    }
    }.start();
      

  3.   

    还不如直接用tasklist |find "cmd.exe"呢。
      

  4.   

    to 楼上们:
    进程名可以相同,PID唯一
    并且,Runtime.getRuntime().exec("*.exe");你如何能准确的知道进程名呢??!
      

  5.   

    tasklist |find "cmd.exe" 怎么用???
      

  6.   

    tasklist |find "cmd.exe"  如果有返回数据 就是cmd.exe这个进程存在
      

  7.   

    JDK 5.0里的bin\jps,再反编译一下看看:)
      

  8.   

    如果两个程序都是自己写的的话,建议两个程序可以通过socket通信,这样比较好,否则的话估计效率会比较低(我认为的,也许java提供更好的方法支持查找的)。
      

  9.   

    YuLimin(阿敏总司令:简单就是美—钻石闪闪您快结贴!)
    JDK 5.0里的bin\jps,再反编译一下看看:)
    用什么工具反编译啊
      

  10.   

    能不能详细一点,怎么然Java执行这个“ Javatasklist |find "cmd.exe"  ”???
      

  11.   

    能不能再详细一点,
    怎么然Java执行这个“ tasklist ¦find "cmd.exe "  ”??? 
    以前没见过这个东西。
      

  12.   

    能不能再详细一点,
    怎么然Java执行这个“ tasklist ¦find "cmd.exe "  ”??? 
    以前没见过这个东西。
      

  13.   

    DJ Java Decompiler可以反编译
      

  14.   

    iwillrockyou(我为java狂~) 说:
          DJ Java Decompiler可以反编译
    什么意思,不明白啊!
      

  15.   

    这样用
    Runtime.getRuntime().exec("tasklist |find "cmd.exe");