Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grunt / PhoneGap : Warning: stdout maxBuffer exceeded

Quite randomly I get the following message Warning: stdout maxBuffer exceeded when I use my grunt script to launch the iOS simulator.

Any idea what could trigger this ?

Here is the part of my Gruntfile where it occurs :

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);
        });
    }
});
like image 299
Matthieu Riegler Avatar asked Mar 09 '14 16:03

Matthieu Riegler


2 Answers

You can use an option to disable maxBuffer :

shell: {
    yourCommand: {
        command: [
            'command to execute'
        ],
        options: {
            execOptions: {
                maxBuffer: Infinity
            }
        }
    }
}
like image 66
ersefuril Avatar answered Nov 05 '22 19:11

ersefuril


When you spawn the child process, try bumping maxBuffer in your config object:

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

According to the docs, the default maxBuffer size is 200 * 1024 (http://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback)

like image 4
darthtrevino Avatar answered Nov 05 '22 20:11

darthtrevino