【问题标题】:How to exec .exe file from Node.js如何从 Node.js 执行 .exe 文件
【发布时间】:2016-09-07 23:19:24
【问题描述】:

我正在使用 NWJS 创建一个简单的桌面应用程序。当我在 html5 上的按钮中执行单击事件时,我需要连接控制台 c++ 应用程序。我听说可以使用 Nodejs 的“child_process”内部模块。单击按钮时,我没有执行 exe 文件。

我有下一个代码:

const exec = require('child_process').execFile;
var cmd = 'Test.exe 1';

exec(cmd, function(error, stdout, stderr) {
    // command output is in stdout
    console.log('stdout:', stdout);
    console.log('stderr:', stderr);
    if (error !== null) {
        console.log('exec error:', error);
    }
});

.exe 文件有一个输入参数(一个数字),它返回一个带有引入数字的简单文本。 谁能帮帮我?

谢谢!

【问题讨论】:

标签: javascript node.js exe node-webkit


【解决方案1】:

我觉得你应该试试这个

child_process.execFile(file[, args][, options][, callback])

file <String> The name or path of the executable file to run
args <Array> List of string arguments
options <Object>

    cwd <String> Current working directory of the child process
    env <Object> Environment key-value pairs
    encoding <String> (Default: 'utf8')
    timeout <Number> (Default: 0)
    maxBuffer <Number> largest amount of data (in bytes) allowed on stdout or stderr - if exceeded child process is killed (Default: 200\*1024)
    killSignal <String> (Default: 'SIGTERM')
    uid <Number> Sets the user identity of the process. (See setuid(2).)
    gid <Number> Sets the group identity of the process. (See setgid(2).)

callback <Function> called with the output when process terminates

    error <Error>
    stdout <String> | <Buffer>
    stderr <String> | <Buffer>

【讨论】:

    猜你喜欢
    • 2013-11-14
    • 2019-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-27
    • 1970-01-01
    相关资源
    最近更新 更多