JavaProcess 類的這個 exitValue() 方法用於返回進程和子進程的退出值。
用法
public abstract int exitValue()
參數
NA
返回
該方法用於返回子進程的退出值。默認情況下,值 0 表示成功終止。
例子1
package tests;
public class ProcessexitValueMethodExample1 {
public static void main(String[] args) {
try{
System.out.println("Let us create a new process");
ProcessBuilder b3 = new ProcessBuilder("notepad.exe");
Process p3= b3.start();
System.out.println("Process is waiting");
Thread.sleep(800);
p3.destroy();
System.out.println("Process is destroyed");
System.out.println("Exit Value:" +p3.exitValue());
}
catch(Exception e){
System.out.println(e);
}
}
}
輸出:
Let us create a new process Process is waiting Process is destroyed Exit Value:1
例子2
package tests;
public class ProcesseexitValueMethodExample2
{
public static void main(String[] args) {
Runtime rt= Runtime.getRuntime();
Process p4=null;
try
{
p4=rt.exec("notepad");
p4.waitFor();
}catch(Exception e)
{
System.out.println(e);
}
if(p4.exitValue()==0)
{
System.out.println("Success");
}
else
{
System.out.println("failure)");
}
}
}
輸出:
Success
相關用法
- Java Process exitValue()用法及代碼示例
- Java Process waitFor()用法及代碼示例
- Java Process Destroy()用法及代碼示例
- Java Process destroy()用法及代碼示例
- Java Process isAlive()用法及代碼示例
- Java Process getOutputStream()用法及代碼示例
- Java Process getInputStream()用法及代碼示例
- Java Process getErrorStream()用法及代碼示例
- Java ProcessBuilder redirectErrorStream()用法及代碼示例
- Java ProcessBuilder environment()用法及代碼示例
- Java ProcessBuilder start()用法及代碼示例
- Java ProcessBuilder directory()用法及代碼示例
- Java Provider keySet()用法及代碼示例
- Java Properties propertyNames()用法及代碼示例
- Java Provider.Service getAttribute()用法及代碼示例
- Java Provider getName()用法及代碼示例
- Java Properties compute(Key, BiFunction)用法及代碼示例
- Java Provider keys()用法及代碼示例
- Java Properties containsKey(value)用法及代碼示例
- Java Properties computeIfAbsent(Key, Function)用法及代碼示例
注:本文由純淨天空篩選整理自 Java Process exitValue() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。