Skip to content

Instantly share code, notes, and snippets.

@gmiroshnykov
Created March 24, 2012 09:54
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save gmiroshnykov/2180730 to your computer and use it in GitHub Desktop.
Save gmiroshnykov/2180730 to your computer and use it in GitHub Desktop.
Spawn a child process and bind it to parent's stdin, stdout and stderr in node.js
var tty = require('tty'),
spawn = require('child_process').spawn;
var child = spawn('vim');
child.stdout.pipe(process.stdout);
child.stderr.pipe(process.stderr);
process.stdin.pipe(child.stdin);
process.stdin.resume();
tty.setRawMode(true);
child.on('exit', function(code, signal) {
process.stdin.pause();
console.log(arguments);
});
@catdad
Copy link

catdad commented Jan 28, 2016

Just curious, did this ever actually work for you? Everything is fine in theory, but I am seeing that about a third of my keystrokes don't make it in and I just end up with random gibberish.

@cancerberoSgx
Copy link

@catdad I think it's because of this : tty.setRawMode(true); try something like package node-pty and will work fine - or more high level : cli-driver

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment