来自节点的Rund咕噜任务并将结果保存在变量中

问题描述:

我想从节点.js文件同步运行一个grunt任务。来自节点的Rund咕噜任务并将结果保存在变量中

它是一个构建过程,所以所有失败的脚本/任务都应该停止构建。

我尝试了

var res = grunt.tasks(['compile']); 
console.log('res: ', res); 

和运行我的编译工作,但没有被存储在res。事实上,我发现任务已经运行了async,因为在任务开始之前日志就出现了。

我该怎么做?

顺便说一句,也

grunt.util.spawn({ 
    grunt: true, 
    args: ['compile'] 
}, function(err, res, code) { 
    console.log('err', err); 
}); 

试过,但没有给出任何输出,只是挡住了我的命令行...

// If specified, the same grunt bin that is currently running will be // spawned as the child command, instead of the "cmd" option.

我读到这里就是spawn代码片段应该与grunt一起运行,而不是直接与node一起运行,因为该问题的标题暗示。

+0

嗯好吧,我明白了。那么还有另外一种方法,我可以在'.js'中运行一个咕噜任务,同步并将其结果存储在一个变量中? – Rikard 2014-08-28 10:50:43

+0

@Rikard是的,像使用其他程序一样将其作为shell命令运行,并获取其输出/错误。 – rollingBalls 2014-08-28 11:00:54