Sha256: a8b46e45c77104656a0ab79fcb95c5cb3434d5b97a36f71c87e6ed0a7730bf58

Contents?: true

Size: 1.04 KB

Versions: 6

Compression:

Stored size: 1.04 KB

Contents

var parse = require('shell-quote').parse;
var exec = require('child_process').exec;
var path = require('path');
var echo = process.execPath + ' ' + path.join(__dirname, 'bin/echo');
var fs = require('fs');

module.exports = function (str, opts) {
    var parts = parse(str);
    for (var i = 0; i < parts.length; i++) {
        if (parts[i].op) break;
    }
    if (i === parts.length) { // no ops
        var w = fs.createWriteStream(str);
        w.once('finish', function () { w.emit('exit', 0) });
        w.once('error', function (err) { w.emit('exit', 1) });
        return w;
    }
    else {
        if (parts[parts.length-1].op === '|') {
            str += echo;
        }
        if (parts[0].op === '|') {
            str = echo + str;
        }
        if (parts[0].op === '>') {
            str = echo + str;
        }
    }
    var p = exec(str, opts);
    p.stderr.pipe(process.stderr, { end: false });
    p.stdout.pipe(process.stdout, { end: false });
    p.once('exit', function (code) { p.stdin.emit('exit', code) });
    return p.stdin;
};

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
brwy_rails-0.0.6 test/dummy/node_modules/outpipe/index.js
brwy_rails-0.0.5 test/dummy/node_modules/outpipe/index.js
brwy_rails-0.0.4 test/dummy/node_modules/outpipe/index.js
brwy_rails-0.0.3 test/dummy/node_modules/outpipe/index.js
brwy_rails-0.0.2 test/dummy/node_modules/outpipe/index.js
brwy_rails-0.0.1 test/dummy/node_modules/outpipe/index.js