<commit_before>var spawn = require('child_process').spawn;
var duplexer = require('duplexer');

module.exports = function (cmd, args) {
    if (Array.isArray(cmd)) {
        args = cmd.slice(1);
        cmd = cmd[0];
    }
    
    var ps = spawn(cmd, args);
    var err = '';
    ps.stderr.on('data', function (buf) { err += buf });
    
    ps.on('exit', function (code) {
        if (code === 0) return;
        dup.emit('error', new Error('non-zero exit code ' + code + ': ' + err));
    });
    
    var dup = duplexer(ps.stdin, ps.stdout);
    return dup;
};<commit_msg>pass through opts and check that stderr exists<commit_after>var spawn = require('child_process').spawn;
var duplexer = require('duplexer');

module.exports = function (cmd, args, opts) {
    if (Array.isArray(cmd)) {
        opts = args;
        args = cmd.slice(1);
        cmd = cmd[0];
    }
    
    var ps = spawn(cmd, args, opts);
    var err = '';
    if (ps.stderr) {
        ps.stderr.on('data', function (buf) { err += buf });
    }
    
    ps.on('exit', function (code) {
        if (code === 0) return;
        dup.emit('error', new Error('non-zero exit code ' + code + ': ' + err));
    });
    
    var dup = duplexer(ps.stdin, ps.stdout);
    return dup;
};
{'fraction_non_alphanumeric': 0.17694155324259409, 'fraction_numerical': 0.004803843074459567, 'mean_word_length': 2.3783783783783785, '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': '4831263', 'n_tokens_mistral': 425, 'n_tokens_neox': 418, 'n_words': 107}