有没有办法退出 Node.js 并在文件上启动 VIM? [英] Is there a way to quit Node.js and launch VIM on a file?

查看:27
本文介绍了有没有办法退出 Node.js 并在文件上启动 VIM?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 Node.js 上创建一个简单的基于终端的文件管理器.有什么办法可以在我的程序在终端上运行时退出并使用 VIM 打开文件?

解决方案

简单:

require('child_process').spawn('vim', ['test.txt'], {stdio: 'inherit'});

如果 vim 退出时 Node.js 事件循环中没有任何内容,那么 node 也会自动退出.或者,如果您需要保证节点会在 vim 执行时退出:

var vim = require('child_process').spawn('vim', ['test.txt'], {stdio: 'inherit'});vim.on('exit', process.exit);

至于在 vim 退出之前 关闭节点应用程序,这实际上是不可能的,因为 vim 继承了生成过程(节点)的标准输入/输出/错误流,这些流在节点退出时被销毁.

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?

解决方案

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.

这篇关于有没有办法退出 Node.js 并在文件上启动 VIM?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆