Node webkit:如何在 MAC 中使用系统默认浏览器打开外部 link
Node webkit: How to open external link with system default browser in MAC
在 windows 中,我使用了这些行
gui = require('nw.gui');
//To open a website externally
gui.Shell.openExternal(URL);
//To execute command line
gui.Shell.openItem(commandString);
它工作正常。同一段代码在 MAC 中不起作用。我在这里错过了什么?我不想创建任何文件并在其中写入命令(批处理文件,通常称为 shell 脚本。)。有没有办法不用创建批处理文件和 运行 这些命令 MAC?
您能否提供您正在测试的完整代码部分?
以下代码片段在 OSX 上运行良好(使用 nw.js 0.12.0
测试):
var gui = require('nw.gui');
gui.Shell.openExternal('http://www.google.com');
另外,gui.Shell.openItem
命令不是用来执行命令的(见Shell documentation)。
您应该使用 nodejs 附带的 child_process
模块:
var exec = require('child_process').exec;
exec(commandString, function (error, stdout, stderr)
{
console.log('stdout:' + stdout);
console.log('stderr:' + stderr);
});
在 windows 中,我使用了这些行
gui = require('nw.gui');
//To open a website externally
gui.Shell.openExternal(URL);
//To execute command line
gui.Shell.openItem(commandString);
它工作正常。同一段代码在 MAC 中不起作用。我在这里错过了什么?我不想创建任何文件并在其中写入命令(批处理文件,通常称为 shell 脚本。)。有没有办法不用创建批处理文件和 运行 这些命令 MAC?
您能否提供您正在测试的完整代码部分?
以下代码片段在 OSX 上运行良好(使用 nw.js 0.12.0
测试):
var gui = require('nw.gui');
gui.Shell.openExternal('http://www.google.com');
另外,gui.Shell.openItem
命令不是用来执行命令的(见Shell documentation)。
您应该使用 nodejs 附带的 child_process
模块:
var exec = require('child_process').exec;
exec(commandString, function (error, stdout, stderr)
{
console.log('stdout:' + stdout);
console.log('stderr:' + stderr);
});