简体   繁体   中英

Grab JVM execution status from bash script

I have a bash script which starts a JVM in the background and then exits. But, many times JVM fails with exceptions. How do I get final execution status, ie, success/failure/errors, in the bash before I exit the bash shell?

JVM is not different from any other process, on failure it returns a non-zero exit code. Script should just pay attention to the exit code. To force it do so add set -e to the beginning of the script, it will start failing on the first failure and simplify the debugging.

Normally, all your production scripts would start with the below combo

#!/usr/bin/env bash
set -eu

And one of many ways to not ignore the exit code of the child process would be

java -cp ... || { echo "child failed" >&2; exit 1; }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM