Yes, this is possible using a SecurityManager. Try the following
class MySecurityManager extends SecurityManager {
@Override public void checkExit(int status) {
throw new SecurityException();
}
@Override public void checkPermission(Permission perm) {
// Allow other activities by default
}
}
In your class use the following calls:
myMethod() {
//Before running the external Command
MySecurityManager secManager = new MySecurityManager();
System.setSecurityManager(secManager);
try {
invokeExternal();
} catch (SecurityException e) {
//Do something if the external code used System.exit()
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…