<commit_before>var process = require('child_process');

function filterOutput(out) {
    return out.split('\n').filter(Boolean);
}

module.exports = function(command, dir, options, done) {
    if (!done && typeof options === 'function') {
        done = options;
        options = {};
    }
    if (!done && !options && typeof dir === 'function') {
        done = dir;
        dir = null;
        options = {};
    }
    if (!options) options = {};

    var execOptions = {};
    var args = [];
    if (dir) execOptions.cwd = dir;
    if (options.args) {
        if (options.args.constructor === Array) {
            args = options.args;
        } else args = options.args.split(" ");
    }

    var arr = command.split(" ").concat(args);
    try {
        var proc = process.spawn(arr.shift(), arr, execOptions);
    } catch (e) {
        done(1, [], [e]);
        return null;
    }

    var outs = "";
    var errs = "";

    proc.stdout.on('data', function(data) {
        outs += data;
        if (options.stdout) options.stdout(data.toString());
    });

    proc.stderr.on('data', function(data) {
        errs += data;
        if (options.stderr) options.stderr(data.toString());
    });

    proc.on('error', function (err) {
        errs+=err;
    });

    proc.on('close', function(code, signal) {
        if (signal === "SIGTERM" && code === null) code = 143;
        if (done) done(code, filterOutput(outs), filterOutput(errs));
    });
    return proc;
};
<commit_msg>proc scope fixed<commit_after>var process = require('child_process');

function filterOutput(out) {
    return out.split('\n').filter(Boolean);
}

module.exports = function(command, dir, options, done) {
    if (!done && typeof options === 'function') {
        done = options;
        options = {};
    }
    if (!done && !options && typeof dir === 'function') {
        done = dir;
        dir = null;
        options = {};
    }
    if (!options) options = {};

    var execOptions = {};
    var args = [];
    if (dir) execOptions.cwd = dir;
    if (options.args) {
        if (options.args.constructor === Array) {
            args = options.args;
        } else args = options.args.split(" ");
    }

    var arr = command.split(" ").concat(args);
    var proc;
    try {
        proc = process.spawn(arr.shift(), arr, execOptions);
    } catch (e) {
        done(1, [], [e]);
        return null;
    }

    var outs = "";
    var errs = "";

    proc.stdout.on('data', function(data) {
        outs += data;
        if (options.stdout) options.stdout(data.toString());
    });

    proc.stderr.on('data', function(data) {
        errs += data;
        if (options.stderr) options.stderr(data.toString());
    });

    proc.on('error', function (err) {
        errs+=err;
    });

    proc.on('close', function(code, signal) {
        if (signal === "SIGTERM" && code === null) code = 143;
        if (done) done(code, filterOutput(outs), filterOutput(errs));
    });
    return proc;
};

{'fraction_non_alphanumeric': 0.17836748404433994, 'fraction_numerical': 0.0026872690628149142, 'mean_word_length': 2.229934924078091, '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': '4459523', 'n_tokens_mistral': 929, 'n_tokens_neox': 910, 'n_words': 217}