使用node.js执行exe文件 [英] Execute an exe file using node.js

查看:6558
本文介绍了使用node.js执行exe文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道如何在 node.js 中执行 exe 文件。这是我正在使用的代码。它不起作用,不打印任何东西。有没有办法使用命令行执行 exe 文件?

I don't know how to execute an exe file in node.js. Here is the code I am using. It is not working and doesn't print anything. Is there any possible way to execute an exe file using the command line?

var fun = function() {
  console.log("rrrr");
  exec('CALL hai.exe', function(err, data) {

    console.log(err)
    console.log(data.toString());
  });
}
fun();


推荐答案

你可以在节点中尝试子进程模块的execFile函数.js

you can try execFile function of child process modules in node.js

参考:
http://nodejs.org/api/child_process.html#child_process_child_process_execfile_file_args_options_callback

您的代码应如下所示:

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();

这篇关于使用node.js执行exe文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆