使用NodeJS和Electron打开外部文件与操作系统的默认应用程序(docx与Word等)

我正在使用NodeJS / Electron作为桌面应用程序。

我想要做的是打开一个文件与它的操作系统的默认应用程序,如.docx与Word。

我到目前为止尝试的方法是使用child_process.spawn,.exec或.exec文件,但我什么也没有得到。

这是我的实际代码:

var fs = require('fs'), cp = require('child_process'); cp.spawn(__dirname + '/test.docx'); 

提前致谢。

使用Electron的shell模块提供的openItem()函数,例如:

 const shell = require('electron').shell; const path = require('path'); shell.openItem(path.join(__dirname, 'test.docx')); 

根据文档, shell模块应该可以在主/浏览器和渲染器进程中使用。