0

I use NodeJs and I want to exec java program and catch the return value from the program - How can I do that?

For example: in NodeJs I got file name as param --> I pass the file name to the java exec program that analyze the file, extract the text and return it.

There is an option to catch the text that the java program return?

1

1 Answer 1

1

This worked for me when I need execute shell commands using nodejs:

const { exec } = require("child_process");

exec("ls -la", (error, stdout, stderr) => {
    if (error) {
        console.log(`error: ${error.message}`);
        return;
    }
    if (stderr) {
        console.log(`stderr: ${stderr}`);
        return;
    }
    console.log(`stdout: ${stdout}`);
});

stdout variable will have the returned text of command

You just change ls -la to java -version or any other java commands

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.