【问题标题】:Method 'exec' doesn't work in grunt task方法 'exec' 在 grunt 任务中不起作用
【发布时间】:2014-07-08 05:55:53
【问题描述】:

我有一个在 grunt config 中注册的任务:

grunt.registerTask('test_Branches',          'Run Branches check on windows',       require('PATH').check);

在我的分支.test.js 中我有方法 check():

this.check = function () {
'use strict';
console.log("Execution started\n");
        exec('git for-each-ref --sort=-committerdate refs/remotes/origin/  --format='%(committername)', {cwd: currentDir}, function (error, stdout, stderr) {
            console.log('started 1.1');
            if (stderr) {
                console.log('stderr: ' + stderr + "\n");
            }
            else {
                console.log("Authors has been received\n");
            }
            if (error !== null) {
                console.log('Execution command error: ' + error + "\n");
            }
        });

};

但是当我试图通过命令行执行我的任务时:

grunt test_Branches

我明白了:

C:\PATH>grunt test_Branches
Running "test_Branches" task
Execution started
Done, without errors.

我的 'exec' 方法有什么问题?

【问题讨论】:

  • 看来我找到了解决方案,伙计们!您需要将grunt.task.current.async(); 与异步函数一起使用。我也是,现在可以了!
  • 好的,谢谢,乔纳森。不幸的是,我不知道那件事,浪费了 2 天时间来找到解决方案:(

标签: javascript node.js asynchronous gruntjs exec


【解决方案1】:

这个问题的解决方案是使用grunt.task.current.async(); 来处理异步函数。正如 Jonathan Lonowski 提到的,here 您可以找到详细信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-31
    • 1970-01-01
    • 1970-01-01
    • 2013-09-11
    • 1970-01-01
    相关资源
    最近更新 更多