Grunt / PhoneGap:警告:超出了stdout maxBuffer

时间:2014-03-09 16:56:50

标签: ios macos cordova gruntjs

当我使用我的grunt脚本启动iOS模拟器时,我得到以下消息Warning: stdout maxBuffer exceeded

知道什么可以触发这个吗?

以下是我的Gruntfile的一部分:

grunt.registerTask('emulator', 'Launch an emulator', function (platform, targetId) {
    if (arguments.length === 0 || !platform) {
        grunt.fail.fatal('No platform was specified');
    } else {
        grunt.log.writeln('We launch the emulator for ' + platform);

        if (targetId) {
            grunt.log.writeln('Specified targetId: ' + targetId);
        }

        var fs = require('fs'), execInstance, directoryPath, command, done = this.async();

        if (platform === 'ios') {
            directoryPath = phoneGapBuildPath + '/platforms/' + platform.toLowerCase() + '/cordova/';
            command = './run';
        } else {
            directoryPath = phoneGapBuildPath + '/platforms/' + platform.toLowerCase() + '/cordova/';
            command = 'node run ' + (targetId ? '--target=' + targetId : '--debug');
        }

        if (!fs.existsSync(directoryPath)) {
            grunt.fail.fatal('You need to launch the compile phase');
            return;
        }

        grunt.log.writeln('We run the following command: ' + command);
        execInstance = require('child_process').exec(command, {
            cwd : directoryPath
        }, function (err) {
            done(err);
        });

        execInstance.stdout.on('data', function (data) {
            grunt.log.writeln(data);
        });
        execInstance.stderr.on('data', function (data) {
            grunt.log.error(data);
        });
    }
});

2 个答案:

答案 0 :(得分:23)

您可以使用选项禁用maxBuffer:

shell: {
    yourCommand: {
        command: [
            'command to execute'
        ],
        options: {
            execOptions: {
                maxBuffer: Infinity
            }
        }
    }
}

答案 1 :(得分:4)

当您生成子进程时,请尝试在配置对象中碰撞maxBuffer:

execInstance = require('child_process').exec(command, {
    cwd : directoryPath,
    maxBuffer: 500 * 1024
}, function (err) {
    done(err);
});

根据文档,默认的maxBuffer大小为200 * 1024(http://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback