Exec : display stdout “live”

前端 未结 9 1172
你的背包
你的背包 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条回答
  •  Happy的楠姐
    2020-11-29 15:43

    I'd just like to add that one small issue with outputting the buffer strings from a spawned process with console.log() is that it adds newlines, which can spread your spawned process output over additional lines. If you output stdout or stderr with process.stdout.write() instead of console.log(), then you'll get the console output from the spawned process 'as is'.

    I saw that solution here: Node.js: printing to console without a trailing newline?

    Hope that helps someone using the solution above (which is a great one for live output, even if it is from the documentation).

提交回复
热议问题