Exec : display stdout “live”

前端 未结 9 1175
你的背包
你的背包 2020-11-29 15:08

I have this simple script :

var exec = require(\'child_process\').exec;

exec(\'coffee -cw my_file.coffee\', function(error, stdout, stderr) {
    console.lo         


        
9条回答
  •  日久生厌
    2020-11-29 15:47

    After reviewing all the other answers, I ended up with this:

    function oldSchoolMakeBuild(cb) {
        var makeProcess = exec('make -C ./oldSchoolMakeBuild',
             function (error, stdout, stderr) {
                 stderr && console.error(stderr);
                 cb(error);
            });
        makeProcess.stdout.on('data', function(data) {
            process.stdout.write('oldSchoolMakeBuild: '+ data);
        });
    }
    

    Sometimes data will be multiple lines, so the oldSchoolMakeBuild header will appear once for multiple lines. But this didn't bother me enough to change it.

提交回复
热议问题