HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/buyercall/node_modules/outpipe/index.js
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;
};