我不知道如何在node.js
中执行exe
文件。这是我正在使用的代码。它不工作,也不打印任何东西。有没有可能使用命令行执行exe
文件?
var fun = function() {
console.log("rrrr");
exec('CALL hai.exe', function(err, data) {
console.log(err)
console.log(data.toString());
});
}
fun();
发布于 2013-11-04 13:55:28
您可以在node.js中试用子进程模块的execFile函数
你的代码应该类似于:
var exec = require('child_process').execFile;
var fun =function(){
console.log("fun() start");
exec('HelloJithin.exe', function(err, data) {
console.log(err)
console.log(data.toString());
});
}
fun();
发布于 2018-12-16 21:56:07
如果要执行的exe
位于其他目录中,并且您的exe
与它所在的文件夹有一些依赖关系,请尝试在选项中设置cwd
参数
var exec = require('child_process').execFile;
/**
* Function to execute exe
* @param {string} fileName The name of the executable file to run.
* @param {string[]} params List of string arguments.
* @param {string} path Current working directory of the child process.
*/
function execute(fileName, params, path) {
let promise = new Promise((resolve, reject) => {
exec(fileName, params, { cwd: path }, (err, data) => {
if (err) reject(err);
else resolve(data);
});
});
return promise;
}
https://stackoverflow.com/questions/19762350
复制相似问题