diff --git a/bin/as.sh b/bin/as.sh index 772591460..c7615b054 100755 --- a/bin/as.sh +++ b/bin/as.sh @@ -393,12 +393,32 @@ update_if_necessary() fi } +# jps command may crash, so need to check it +check_jps() { + "${JAVA_HOME}/bin/jps" > /dev/null 2>&1 + local exit_code=$? + if [ $exit_code -ne 0 ]; then + echo "jps command failed with exit code ${exit_code}" >&2 + fi + return $exit_code +} + call_jps() { - if [ "${VERBOSE}" = true ] ; then - "${JAVA_HOME}"/bin/jps -l -v + check_jps + local exit_code=$? + if [[ "$exit_code" -eq 0 ]]; then + # jps command is ok + local jps_command=("${JAVA_HOME}/bin/jps" "-l") + if [ "${VERBOSE}" = true ] ; then + jps_command=("${JAVA_HOME}/bin/jps" "-l" "-v") + fi + local jps_output=$("${jps_command[@]}") + echo "$jps_output" else - "${JAVA_HOME}"/bin/jps -l + # jps command failed, use ps and grep + ps_output=$(ps aux | grep java | grep -v grep | awk '{print $2" "$11}') + echo "$ps_output" fi }