Nodejs 打开 ppt、doc 或任何其他文件
Nodejs open ppt, doc or any other files
我一直在尝试执行系统中的任何文件,并在系统的默认应用程序中打开它。
For example I have abc.doc file, and i want to open it in Microsoft Word.
此代码在默认浏览器中打开 URL。
var open = require('open');
open('http://www.google.com', function (err) {
if (err) throw err;
console.log('The user closed the browser');
});
关于如何通过节点 js 在默认应用程序中打开系统文件的任何建议。
use exec from shelljs
示例如下:
var shell = require('shelljs');
shell.exec("D://yourdocument.pdf", function (err, out, code)) {
if(err instanceof Error)
throw err;
});
希望对您有所帮助。谢谢
在windows中你可以简单地给出文件路径。但是在 linux 或 mac os 中,您还需要添加 xdg-open 前缀才能在默认应用程序中打开。
Linux Code & Mac OS
shell.exec("xdg-open /home/file.extension", function (err, out, code)) { /* your statements */ });
Windows Code
shell.exec("C:/file.extension", function (err, out, code)) { /* your statements */ });
我一直在尝试执行系统中的任何文件,并在系统的默认应用程序中打开它。
For example I have abc.doc file, and i want to open it in Microsoft Word.
此代码在默认浏览器中打开 URL。
var open = require('open');
open('http://www.google.com', function (err) {
if (err) throw err;
console.log('The user closed the browser');
});
关于如何通过节点 js 在默认应用程序中打开系统文件的任何建议。
use exec from shelljs
示例如下:
var shell = require('shelljs');
shell.exec("D://yourdocument.pdf", function (err, out, code)) {
if(err instanceof Error)
throw err;
});
希望对您有所帮助。谢谢
在windows中你可以简单地给出文件路径。但是在 linux 或 mac os 中,您还需要添加 xdg-open 前缀才能在默认应用程序中打开。
Linux Code & Mac OS
shell.exec("xdg-open /home/file.extension", function (err, out, code)) { /* your statements */ });
Windows Code
shell.exec("C:/file.extension", function (err, out, code)) { /* your statements */ });