簡體   English   中英

如何在Grunt中的循環內執行Shell命令?

[英]How to execute shell commands inside a loop in Grunt?

我有一個包含多個子文件夾的應用程序文件夾。 我正在遍歷這些文件夾,並嘗試為每個文件夾運行一個shell命令。 這是我到目前為止所擁有的:

grunt.registerTask('deploy', function() {

    var done = this.async();
    var exec = require('child_process').exec;

    // Start deployment
    grunt.log.write('Starting deployment...').ok();

    // Read all subdirectories from the app folder
    grunt.file.expand("./app/*").forEach(function (dir) {

        // Get folder name
        var functionName = dir.split('/')[2];

        exec('echo ' + functionName, {
            cwd: dir
        }, function(error, stdout, stderr) {
            grunt.log.ok(functionName+' deployed.');
            done();
        });

    });

});

我希望在終端中打印出每個文件夾名稱,但是我所得到的只是exec函數中的回調,如下所示:

Running "deploy" task
Starting deployment...OK
>> testA deployed.
>> testB deployed.

我不確定自己在做什么錯。

該命令的輸出可以在傳遞給回調的stdout變量中找到。 它不會自動打印終端。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM