[英]Run shell command from JavaScript in node-webkit?
Is there any way to run shell command from JavaScript in node-webkit? 有没有办法在node-webkit中从JavaScript运行shell命令? There is a lot of similar questions, but it didn't help me.
有很多类似的问题,但它对我没有帮助。
I'm trying to build simple desktop app for listing installed tools. 我正在尝试构建简单的桌面应用程序以列出已安装的工具。 I've created node module 'tools-v' which is installed globally and works when I run it in command line.
我已经创建了全局安装的节点模块'tools-v',当我在命令行中运行它时可以工作。 This module run several commands:
npm -v
, node -v
, git -v
etc. I'm on Windows 7. 这个模块运行几个命令:
npm -v
, node -v
, git -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);
}
});
});
I'm always getting error: ""exec error: Error: spawn ENOENT""
我总是收到错误:
""exec error: Error: spawn ENOENT""
I tried spawn instead of exec. 我尝试了spawn而不是exec。 I also tried several other commands, beside node module.
我还在节点模块旁边尝试了其他几个命令。 Thanks.
谢谢。
Actually, this code works. 实际上,这段代码有效。 I just didn't built full app, I tested it trough sublime build for node-webkit.
我刚刚没有构建完整的应用程序,我通过sublime build for node-webkit进行了测试。 Preforming full build with grunt solved every
spawn
issues. 使用grunt进行完整构建解决了每个
spawn
问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.