1

I am writing some code that lists some functionalities which are run by cmd, How can I enclose cmd executables in my code?

2 Answers 2

1

Here is a small example to use child_process.

Execute command in cmd.

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

function os_func() {
    this.execCommand = function(cmd, callback) {
        exec(cmd, (error, stdout, stderr) => {
            if (error) {
                console.error(`exec error: ${error}`);
                return;
            }

            callback(stdout);
        });
    }
}

app.get("/", (req, res) => {
    console.log("inside get");
    var os = new os_func();
    os.execCommand('arp -a', function (returnvalue) {
      res.end(returnvalue)
});

});

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

Comments

0

There is a global function i.e: process.argv

Or if you want to take command-line arguments a lot better try npm package yargs.

1 Comment

I have been using process.env, and I set the root for cmd, but it seems not working.

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.