<commit_before>var spawn = require('cross-spawn');
var createError = require('err-code');
var Q = require('q');

function execute(command, args, options) {
    var process;
    var stderr = new Buffer('');
    var stdout = new Buffer('');
    var deferred = Q.defer();

    // Buffer output, reporting progress
    process = spawn(command, args, options);
    process.stdout.on('data', function (data) {
        stdout = Buffer.concat([stdout, data]);
        deferred.notify(data);
    });
    process.stderr.on('data', function (data) {
        stderr = Buffer.concat([stderr, data]);
        deferred.notify(data);
    });

    // If there is an error spawning the command, reject the promise
    process.on('error', function (error) {
        return deferred.reject(error);
    });

    // Listen to the close event instead of exit
    // They are similar but close ensures that streams are flushed
    process.on('close', function (code) {
        var fullCommand;
        var error;

        stdout = stdout.toString();
        stderr = stderr.toString();

        if (!code) {
            return deferred.resolve([stdout, stderr]);
        }

        // Generate the full command to be presented in the error message
        if (!Array.isArray(args)) {
            args = [];
        }

        fullCommand = command;
        fullCommand += args.length ? ' ' + args.join(' ') : '';

        // Build the error instance
        error = createError('Failed to execute "' + fullCommand + '", exit code of #' + code, 'ECMDERR', {
            stderr: stderr,
            stdout: stdout,
            details: stderr,
            status: code
        });

        return deferred.reject(error);
    });

    deferred.promise.cp = process;

    return deferred.promise;
}

function buffered(command, args, options, callback) {
    if (typeof options === 'function') {<commit_msg>Simplify.<commit_after>var spawn = require('cross-spawn');
var createError = require('err-code');
var Q = require('q');

function execute(command, args, options) {
    var process;
    var stderr = new Buffer('');
    var stdout = new Buffer('');
    var deferred = Q.defer();

    // Buffer output, reporting progress
    process = spawn(command, args, options);
    process.stdout.on('data', function (data) {
        stdout = Buffer.concat([stdout, data]);
        deferred.notify(data);
    });
    process.stderr.on('data', function (data) {
        stderr = Buffer.concat([stderr, data]);
        deferred.notify(data);
    });

    // If there is an error spawning the command, reject the promise
    process.on('error', function (error) {
        return deferred.reject(error);
    });

    // Listen to the close event instead of exit
    // They are similar but close ensures that streams are flushed
    process.on('close', function (code) {
        var fullCommand;
        var error;

        stdout = stdout.toString();
        stderr = stderr.toString();

        if (!code) {
            return deferred.resolve([stdout, stderr]);
        }

        // Generate the full command to be presented in the error message
        args = args || [];
        fullCommand = command;
        fullCommand += args.length ? ' ' + args.join(' ') : '';

        // Build the error instance
        error = createError('Failed to execute "' + fullCommand + '", exit code of #' + code, 'ECMDERR', {
            stderr: stderr,
            stdout: stdout,
            details: stderr,
            status: code
        });

        return deferred.reject(error);
    });

    deferred.promise.cp = process;

    return deferred.promise;
}

function buffered(command, args, options, callback) {
    if (typeof options === 'function') {
{'fraction_non_alphanumeric': 0.13184146670261526, 'fraction_numerical': 0.0, 'mean_word_length': 2.324372759856631, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2285851', 'n_tokens_mistral': 1028, 'n_tokens_neox': 979, 'n_words': 307}