Method 'exec' doesn't work in grunt ta

2019-09-16 17:46发布

问题:

I have a task that registred in grunt config:

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

And in my branches.test.js I have method 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");
            }
        });

};

But when I'm trying to execute my task through command line with command:

grunt test_Branches

I got:

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

What's the problem with my 'exec' method?

回答1:

The solution for this problem is using grunt.task.current.async(); for asynchronous functions. As Jonathan Lonowski mentioned, here you can find details.