Skip to content

Instantly share code, notes, and snippets.

@Floby
Created April 19, 2011 09:18
Embed
What would you like to do?
open the default editor from node
var fs = require('fs');
var child_process = require('child_process');
var spawn = child_process.spawn;
function openEditor(file) {
var cp = spawn(process.env.EDITOR, [file], {
customFds: [
process.stdin,
process.stdout,
process.stderr
]
});
cp.on('exit', function() {
console.log('editor ended');
var content = fs.readFileSync(file, 'utf8');
console.log(content);
});
}
child_process.exec('mktemp', function(err, stdout, stderr) {
if(err) {
console.log(err);
return;
}
// remove the \n
openEditor(stdout.substr(0, stdout.length-1));
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment