如何从 Node.js 执行 .exe 文件
How to exec .exe file from Node.js
我正在使用 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 文件有一个输入参数(一个数字),它 returns 一个带有引入数字的简单文本。
谁能帮帮我?
谢谢!
我觉得你应该试试这个
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>
我正在使用 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 文件有一个输入参数(一个数字),它 returns 一个带有引入数字的简单文本。 谁能帮帮我?
谢谢!
我觉得你应该试试这个
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>