I have a nodejs function which calls a ShellScript xyz.sh. This shell script executes a jar file abc.jar and prints some output in the console. I am able to see some output lines from jar file execution in the console. But I am not able to capture them lets say to a variable. My requirement is to capture the error while executing logic present in jar file. Try catch is not helping here. Also, I cannot edit the java code and rebuild the jar file. But I would need to capture the output of jar file execution somehow in Nodejs and in case of errors while executing logic inside jar file, I need to take certain actions based on the error. So, can someone help me on how to capture the output of jar file in nodejs.
private async function_exec(abc: string) {
log.info('inside func_exec')
let result;
try
{
result = await asyncExec(
call xyz.sh; --> shell script gets called here
)
}
catch(error)
{
log.info('error is '+error);
}
log.info('result is '+result);
}
Output looks like below. I need to somehow capture messages like "Processing..",'Failed to Execute","Invalid system ID"
output:
runn_1 inside func_exec
runn_1 Processing..
runn_1 Failed to Execute
runn_1 Invalid system ID
runn_1 error is 1
runn_1 result is undefined