• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Catch Java exit code in linux script when Java program is executed using maven plugin

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am trying to catch the java exit code in a shell script and have not been successful so far
I couldn't fine much on google as well

In my shell script I ran java program using mvn



the Java program successfully exits with different exit code of 2 which I can see from mvn plugin output



However $? prints bash: 0: command not found

Is there a way we can achieve this?

Many thanks in advance


 
Sheriff
Posts: 4870
317
IntelliJ IDE Python Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The return code you see in your script is coming from Maven, not your Java application. I'm not aware of any way to have Maven use the app return code, nor would I expect it to as the Maven return code is an indicator of the state of the Maven run not the application behaviour.

I recommend you enhance your script to use Maven to build the Java application, then as a second step run it directly from which you can observe the return code.
 
Ranch Hand
Posts: 356
2
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
are you using linux/mac ?
 
Sheriff
Posts: 7108
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
According to the subject line, it's Linux.
 
German Gonzalez-Morris
Ranch Hand
Posts: 356
2
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right, I didn't see it.

it's strange because it seems that the error message is from bash itself.

So you are not using "echo":






 
I guess I've been abducted by space aliens. So unprofessional. They tried to probe me with this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic