Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Start a Spring-Shell based application not interactive

Tags:

spring-shell

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.

like image 347
Cengiz Avatar asked Aug 22 '14 17:08

Cengiz


2 Answers

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.

like image 150
ebottard Avatar answered Nov 14 '22 14:11

ebottard


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
like image 23
Greg St.Onge Avatar answered Nov 14 '22 13:11

Greg St.Onge