function readin(cb) { var stdin = process.openStdin(), data = ''; stdin.setEncoding('utf8'); stdin.addListener('data', function (chunk) { data += chunk; }); stdin.addListener('end', function () { cb(data); }); }
if (tokens.length === 0) { console.log("command requires at least one token") process.exit(0) } var proc = tokens[0] var args = tokens.slice(1) var child = child_process.spawn(proc, args, {detached: true}); child.stdout.on('data', function(data) { console.log(data.toString('utf8')) }) child.stderr.on('data', function(data) { console.error(data.toString('utf8')) }) function endAll() { process.kill(-child.pid) process.exit(0) } var stdin = process.openStdin() stdin.on('end', function() { endAll() }) process.on('SIGINT', function() { endAll() })
#! /usr/bin/env node 'use strict'; const inquirer = require('inquirer'); const safename = require('safename'); const fs = require('fs'); const process = require('process'); const spawn = require('child_process').spawn; const stdin = process.openStdin(); process.stdin.setRawMode(true); stdin.resume(); const GitCommandLine = require('git-command-line'); const Git = new GitCommandLine(); const StringDecoder = require('string_decoder').StringDecoder; const decoder = new StringDecoder('utf8'); const program = require('commander'); const pkg = require('./package.json'); program .version(pkg.version) .usage('<git repo> [options]') .option('-r, --run [command]', 'run command') .option('-o, --open [command]', 'open command') .parse(process.argv);