node进程捕捉错误

var childProcess = require('child_process');
var commitMessage = (function() {
	var spawn = childProcess.spawnSync(<common>, <param>);
	var errorText = spawn.stderr.toString().trim();
	if (errorText) {
	  console.log('Fatal error from `git log`.  You must have one commit before deploying.');
	  throw new Error(errorText);
	}
	else {
	  return spawn.stdout.toString().trim();
	}
})();
posted @ 2018-07-14 17:59  wanhong  阅读(363)  评论(0)    收藏  举报