Nodejs中运行系统命令runlinuxcommandinnodejs不要在jmk中编译coffee!
refer to: http://stackoverflow.com/questions/4443597/node-js-execute-system-command-synchronously
最新的版本 (0.12.0) ,以及包含了 execSync.
解决办法: 使用 execSync. 完整例子如下:
(注意: 这个例子不适用于 tishadow, 因为tishadow 在重新编译alloy时,一旦编译coffee文件,那么 tishadow 就会被循环出发. 所以,不要在 jmk 文件中 适用 pre:compile来编译 coffee文件 )
// 文件: app/alloy.jmk
// 编译 alloy 之前,先编译coffee
// 需要安装 $ npm install execSync
task("pre:compile",function(event,logger){
logger.showTimestamp = true;
logger.info("=== before compile alloy");
folder = event.dir.project;
var sh = require('execSync'); // 这里是关键1
// 所有的待编译文件,使用绝对路径
command = 'cat ' + folder + '/app/controllers/home/home_*.coffee | coffee -bc --stdio > '
+ folder + '/app/controllers/home.js ';
logger.info("command: " + command);
result= sh.run(command); // 关键2
logger.info(result)
command = 'coffee -bc ' + folder + '/app/controllers/*.coffee';
logger.info("command: " + command);
result= sh.run(command);
logger.info(result)
logger.info("=== after compile alloy");
});