Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

96
Views
Capture console output of shellscript in nodejs

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
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!