how to wait for an exec command to fininsh in nodejs

Solutions on MaxInterview for how to wait for an exec command to fininsh in nodejs by the best coders in the world

showing results for - "how to wait for an exec command to fininsh in nodejs"
Heath
17 Jul 2016
1const exec = require('child_process').exec;
2
3function os_func() {
4    this.execCommand = function(cmd, callback) {
5        exec(cmd, (error, stdout, stderr) => {
6            if (error) {
7                console.error(`exec error: ${error}`);
8                return;
9            }
10
11            callback(stdout);
12        });
13    }
14}
15var os = new os_func();
16
17os.execCommand('SomeCommand', function (returnvalue) {
18    // Here you can get the return value
19});