4

Is there any way to run shell command from JavaScript in node-webkit? 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. This module run several commands: npm -v, node -v, git -v etc. I'm on 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""

I tried spawn instead of exec. I also tried several other commands, beside node module. Thanks.

1 Answer 1

1

Actually, this code works. I just didn't built full app, I tested it trough sublime build for node-webkit. Preforming full build with grunt solved every spawn issues.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.