I'm creating a simple terminal-based file manager on Node.js. Is there any way I can, from while my program is running on the terminal, quit it and open a file with VIM?
问问题
979 次
1 回答
8
Simply:
require('child_process').spawn('vim', ['test.txt'], {stdio: 'inherit'});
If there is nothing left in the Node.js event loop when vim exits, then node will exit automatically as well. Or, if you need to guarantee node will exit when vim does:
var vim = require('child_process').spawn('vim', ['test.txt'], {stdio: 'inherit'});
vim.on('exit', process.exit);
As for closing the node application before vim exits, that's not really possible because vim inherits standard input/output/error streams from the spawning process (node) which are destroyed when node exits.
于 2013-03-31T05:55:38.807 回答