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.
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.
我的代码如下:
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.
{ 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())
}
你写的p.waitfor()让process等待了,他那个dos命令都不执行了阿.还是不行.
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());
}