Exec : display stdout “live”

前端 未结 9 1163
你的背包
你的背包 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:25

    There are already several answers however none of them mention the best (and easiest) way to do this, which is using spawn and the { stdio: 'inherit' } option. It seems to produce the most accurate output, for example when displaying the progress information from a git clone.

    Simply do this:

    var spawn = require('child_process').spawn;
    
    spawn('coffee', ['-cw', 'my_file.coffee'], { stdio: 'inherit' });
    

    Credit to @MorganTouvereyQuilling for pointing this out in this comment.

提交回复
热议问题