【问题标题】:Run shell command from JavaScript in node-webkit?在 node-webkit 中从 JavaScript 运行 shell 命令?
【发布时间】:2015-01-11 07:17:41
【问题描述】:

有没有办法在 node-webkit 中从 JavaScript 运行 shell 命令? 有很多类似的问题,但对我没有帮助。

我正在尝试构建简单的桌面应用程序来列出已安装的工具。 我创建了全局安装的节点模块“tools-v”,当我在命令行中运行它时可以工作。 该模块运行多个命令:npm -vnode -vgit -v 等。 我在 Windows 7 上。

//var sys = require('sys');
var exec = require('child_process').exec;
//var toolsv = (process.platform === "win32" ? "tools-v.cmd" : "tools-v");
$(document).ready(function() {
    //myCmd = "C:\\Users\\win7\\AppData\\Roaming\\npm\\tools-v.cmd";
    //myCmd = toolsv;
    myCmd = 'tools-v';
    //gui.Shell.openItem('firefox',function(error, stdout, stderr) { });
    //opening Firefox works.
    exec(myCmd,  function (error, stdout, stderr) {
        //detached: true;
        console.log('stdout: ' + stdout);
        $('#output').append('stdout: ' + stdout)
        if (error !== null) {
          console.log('exec error: ' + error);
        }
    });
});

我总是遇到错误: ""exec error: Error: spawn ENOENT""

我尝试了 spawn 而不是 exec。除了节点模块,我还尝试了其他几个命令。 谢谢。

【问题讨论】:

    标签: javascript node.js shell desktop-application node-webkit


    【解决方案1】:

    实际上,此代码有效。我只是没有构建完整的应用程序,我通过 node-webkit 的 sublime build 对其进行了测试。使用 grunt 执行完整构建解决了每个 spawn 问题。

    【讨论】:

      猜你喜欢
      • 2014-09-22
      • 1970-01-01
      • 2013-11-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-13
      • 2011-03-03
      相关资源
      最近更新 更多