我不知道如何在
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();
您可以在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();
如果要执行的
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);