20

I am developing a Java program using Eclipse that should exit with different codes based on the specific conditions.

if(veryBadError){
    Runtime.getRuntime().exit(10);
}else if(notSoBadError){
    Runtime.getRuntime().exit(5)
}else{
    Runtime.getRuntime().exit(0)
}

Currently I manually run this program from command line and then check exit status, which is ridiculously slow. Is there a way to find out exit code without leaving Eclipse IDE?

Thanks in advance for help!

Dima
  • 1,788
  • 2
  • 22
  • 30
  • Hi. I have an extention to this problem. How can i get the value in a JUnit test case. See - http://stackoverflow.com/questions/11505109/how-to-get-the-value-that-is-passed-to-runtime-getruntime-exitvalue-in-a-junit – JHS Jul 16 '12 at 13:25

3 Answers3

26

In Eclipse, if you open up the "Debug Perspective" you should see the result of your execution there (whether you use a Run target or a Debug target). You should see an entry that looks something like:

<terminated, exit value: 10>/usr/local/bin/java (Jun 9, 2011 4:00:00 PM)

Your exit code should be the value after "exit value".

spdaley
  • 811
  • 7
  • 7
3

It is in "Debug" view.

You can get it:

  1. By switching to Debug perspective
  2. Or from: Menu > Windows > Show View > Other > Debug/Debug

enter image description here

Witold Kaczurba
  • 9,845
  • 3
  • 58
  • 67
2

You can set up a run configuration in Eclipse. From there, you can see the program's output in the console. From the 'Run' menu, you can 'Run As' your configuration. Your configuration can include all of the command line args and stuff like that.

You could also use Junit to test your program. Here is a link to another post with several ways to do that.

Community
  • 1
  • 1
revdrjrr
  • 1,025
  • 1
  • 8
  • 16