在node-webkit中使用默认程序打开一个文件 [英] open a file with default program in node-webkit
本文介绍了在node-webkit中使用默认程序打开一个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想为用户提供他想要编辑文件的任何选项,如何使用特定文件类型的默认程序打开文件?我需要它与Windows和Linux一起使用,但Mac选项也会很棒。
I want to give the user any option he want to edit a file, how can I open a file with the default program of the specific file type? I need it to work with Windows and Linux but Mac option would be great too.
推荐答案
正如PSkocik所说,首先检测平台并获取命令行:
as PSkocik said, first detect the platform and get the command line :
function getCommandLine() {
switch (process.platform) {
case 'darwin' : return 'open';
case 'win32' : return 'start';
case 'win64' : return 'start';
default : return 'xdg-open';
}
}
秒,执行命令行后跟路径
second , execute the command line followed by the path
var sys = require('sys');
var exec = require('child_process').exec;
exec(getCommandLine() + ' ' + filePath);
这篇关于在node-webkit中使用默认程序打开一个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文