System.exit(0)和System.exit(-1)之间的区别 [英] difference between System.exit(0) and System.exit(-1)
问题描述
任何人都可以分享 System.exit(0)
和 System.exit(-1)
如果你用例子解释它会很有用。
Can any one share to me difference between System.exit(0)
and System.exit(-1)
it is helpful if you explain with example.
推荐答案
这只是流程退出代码的区别。因此,如果有任何事情要根据退出代码采取行动(其中0通常是成功,非零通常表示错误),您可以控制他们看到的内容。
It's just the difference in terms of the exit code of the process. So if anything was going to take action based on the exit code (where 0 is typically success, and non-zero usually indicates an error) you can control what they see.
例如,使用这个小型Java程序,它使用命令行参数的数量作为退出代码:
As an example, take this tiny Java program, which uses the number of command line arguments as the exit code:
public class Test {
public static void main(String[] args) throws Exception {
System.exit(args.length);
}
}
现在从bash shell运行它,其中&&
表示如果第一个命令成功,则执行第二个命令我们可以:
Now running it from a bash shell, where &&
means "execute the second command if the first one is successful" we can have:
~ $ java Test && echo Success!
Success!
~ $ java Test boom && echo Success!
这篇关于System.exit(0)和System.exit(-1)之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!