如何从节点脚本执行时查看bash命令

我有一个节点应用程序,我使用bitbucket中的webhook来触发bash脚本来运行一些命令来部署我的应用程序。 它工作,但是我不能查看任何正在运行的命令(即进度命令echo'd)。 我怎样才能做到这一点?

这是相关的代码:

var shellPath = path.join(__dirname + '../../deploy/deploy.sh'); var exec = require('child_process').exec; function puts(error, stdout, stderr) { console.log('stout: ', stdout) console.log('error: ', error) console.log('stderr: ', stderr) } exec(shellPath, puts); 

deploy.sh –

 echo Preparing to Git Fetch git reset --hard origin/master echo Preparing to clean git clean -f echo Preparing to pull git pull echo preparing to pull npm i --production echo preparing to restart pm2 pm2 restart client-www echo Finished deploy 

你可以输出结果到一个文件,如:

 var shellPath = path.join(__dirname + '../../deploy/deploy.sh > ./output.log'); var exec = require('child_process').exec; function puts(error, stdout, stderr) { console.log('stout: ', stdout) console.log('error: ', error) console.log('stderr: ', stderr) } exec(shellPath, puts); 

并用它来观看文件和打印输出总是尾巴

 var Tail = require('always-tail'); var fs = require('fs'); var filename = "./output.log"; if (!fs.existsSync(filename)) fs.writeFileSync(filename, ""); var tail = new Tail(filename, '\n'); tail.on('line', function(data) { console.log("got line:", data); }); tail.on('error', function(data) { console.log("error:", data); }); tail.watch();