我正在尝试在Node.js脚本中使用以下命令打开Unix文本编辑器(在此示例中为nano
):
if (process.argv[2] === 'edit') {
require('child_process').spawn("sudo", ["nano", dbFile], {
stdio: 'inherit'
});
process.exit(); // try to block here in order not to execute rest of code in this file
}
这会打开nano
,但是文本很奇怪,而且我无法输入任何内容。
("nano " + dbFile).split(' ')
应该是["nano", dbFile]
。 - undefined