javascript - Node - child process spawn path - Stack Overflow

I would like to run an exe in Windows from my Node Webkit app.I am trying the below code but it is not

I would like to run an exe in Windows from my Node Webkit app.

I am trying the below code but it is not working.

document.getElementById('play').onclick = function()
{
    var spawn = require('child_process').spawn;
    var child = spawn(__dirname + '/core.exe', ['/arg1']);

    var snd = new Audio("min.wav"); 
    snd.play();
    win.minimize();

    child.stdout.on('data', function (data) {
        console.log('stdout: ' + data);
    });

    child.stderr.on('data', function (data) {
        console.log('stderr: ' + data);
    });

    child.on('close', function (code) {
        console.log('child process exited with code ' + code);
        var snd = new Audio("restore.wav"); 
        snd.play();
        win.restore();
    });
}

Am I getting the path wrong? I need it to be current directory and run the exe with that name and the example arg.

The output SHOULD be a messagebox, but nothing loads.

I would like to run an exe in Windows from my Node Webkit app.

I am trying the below code but it is not working.

document.getElementById('play').onclick = function()
{
    var spawn = require('child_process').spawn;
    var child = spawn(__dirname + '/core.exe', ['/arg1']);

    var snd = new Audio("min.wav"); 
    snd.play();
    win.minimize();

    child.stdout.on('data', function (data) {
        console.log('stdout: ' + data);
    });

    child.stderr.on('data', function (data) {
        console.log('stderr: ' + data);
    });

    child.on('close', function (code) {
        console.log('child process exited with code ' + code);
        var snd = new Audio("restore.wav"); 
        snd.play();
        win.restore();
    });
}

Am I getting the path wrong? I need it to be current directory and run the exe with that name and the example arg.

The output SHOULD be a messagebox, but nothing loads.

Share Improve this question asked Jul 30, 2017 at 22:12 BolteBolte 1413 silver badges14 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

Managed to figure it out, it wasn't defined because I was using it in browser context. I didn't get the nw.js SDK version for some reason, found that __DIRNAME was undefined. Came up with this solution instead.

    var path = require('path');
    var nwDir = path.dirname(process.execPath);
    var spawn = require('child_process').spawn;
    var child = spawn(nwDir + '/app/core.exe', ['/arg1']);

Now working as intended.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745451956a4628311.html

相关推荐

  • javascript - Node - child process spawn path - Stack Overflow

    I would like to run an exe in Windows from my Node Webkit app.I am trying the below code but it is not

    5小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信