5

Is it possible to start a specific command of a Spring-Shell app and then return/exit the shell after the command is finished? Further is it possible to expose the exit code (System.exit) of the app to the operating system shell?

For my purpose i will take advantage of the plugin mechanism and the CLI-Annotations of Spring-Shell. But in general there is no human interaction with the app, instead a job scheduler (UC4) will start the app and check the exit code to generate an email in case of an exit code not equal to 0. On the other hand for manual tests by our customer, there is also the need of tab completion, usage help etc.

Cengiz
  • 4,898
  • 6
  • 45
  • 72

2 Answers2

6

This behavior is already built-in (although we considered removing it, or at least make it optional). I see now that it is useful :)

Simply invoke the shell with your (sole) command and the shell will spin up, execute the command, and quit. Also, the return code of the shell already indicates whether there was an error or not (tried with an inexistant command for example). Of course, if your custom commands do not properly indicate an error (i.e. print an error message but perform a normal return) this will not work. You should throw an exception instead.

ebottard
  • 1,987
  • 2
  • 11
  • 14
  • 2
    It seems this support is removed in 2.0. A link to the documentation for the best practices to use it in latest version would make this answer a bit better. – рüффп Sep 18 '18 at 12:06
  • Yeah, it's a pity they removed it, @ebottard, why was it removed? :( – oblio Jan 25 '19 at 11:44
1

The behavior is back.

Run spring-shell with @my-script, like so:

java -jar my-app.jar @my-script

Where my-script is a file with your commands:

my-command1 arg1 arg2
my-command2 arg1 arg2