exitValue
public abstract int exitValue()Returns the exit value for the subprocess.
Returns:
the exit value of the subprocess represented by this Process object. by convention, the value 0 indicates normal termination.
Throws:
IllegalThreadStateException - if the subprocess represented by this Process object has not yet terminated.

解决方案 »

  1.   

    那个我试验过了,不行,
    我的代码如下:
    int exitcode=1000;
    try
    {
    Process p = Runtime.getRuntime().exec(command);
    p.exitValue();
    }
    catch (Exception ex)
    {
     System.err.println("Command invoke error in UtilTools.invokeCommand..."+ex.toString());
    }
    这样在执行的过程中会打出the process not finished.
      

  2.   

    try
    {    Process p = Runtime.getRuntime().exec(command);
        p.exitValue();
        try
        {
            proc.waitFor();
        }
        catch(InterruptedException e)
        {
            System.err.println("process was interrupted");
        }
        //判断命令执行是否结束
        if(proc.exitValue() != 0)
            System.err.println("exit value was non-zero");}
    catch(IOException ioe)
    {
        System.err.println("error: "+ioe.toString())
    }
      

  3.   

    to: cawangjun(心驿) 
    你写的p.waitfor()让process等待了,他那个dos命令都不执行了阿.还是不行.
      

  4.   

    你运行那个程序了没有啊?我试了,对的啊关键是那个dos命令没有输出,这个你要注意,有可能因为等待输入而阻塞
      

  5.   

    这个是我的大概程序,因为那个目录下的东西很多,所以拷贝需要至少10秒,所以有问题、
    String command = "xcopy "+
                             getSpirits2Config.getTomcatHome()+
                             "\\webapps\\"+
                             getSpirits2Config.getOldProjectName()+
                             "  "+
                             getSpirits2Config.getTomcatHome()+
                             "\\webapps\\"+
                             getSpirits2Config.getNowProjectName()+
                             "\\ /s";
            System.out.println("command="+command);
            invokeCommand(command);
    public static void invokeCommand(String command)
    {
    try
            {
                Process p = Runtime.getRuntime().exec(command);
                p.waitFor();
                if(p.exitValue() != 0)
                {
                    System.out.println("exit error");
                }
            }
            catch (Exception ex)
            {
                System.err.println("Command invoke error in UtilTools.invokeCommand..."+ex.toString());
            }