📜  如何在 nodejs 中等待 exec 命令完成 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:04.829000             🧑  作者: Mango

代码示例1
const exec = require('child_process').exec;

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

            callback(stdout);
        });
    }
}
var os = new os_func();

os.execCommand('SomeCommand', function (returnvalue) {
    // Here you can get the return value
});