javascript - Node.JS: execFile ENOENT - Stack Overflow

I've tried to execute *.exe file, but got:exec error:{ Error: spawn ${__dirname}install.exe ENO

I've tried to execute *.exe file, but got:

exec error: { Error: spawn ${__dirname}/install.exe ENOENT

Code:

var execFile = require('child_process').execFile
execFile('${__dirname}/install.exe', function(error, stderr) {
   console.log('stderr: ', __dirname);
   if (error !== null) {
       console.log('exec error: ', error);
   }
  });

Also tried: '${__dirname}\install.exe', './install.exe', 'D:\install.exe'

I've tried to execute *.exe file, but got:

exec error: { Error: spawn ${__dirname}/install.exe ENOENT

Code:

var execFile = require('child_process').execFile
execFile('${__dirname}/install.exe', function(error, stderr) {
   console.log('stderr: ', __dirname);
   if (error !== null) {
       console.log('exec error: ', error);
   }
  });

Also tried: '${__dirname}\install.exe', './install.exe', 'D:\install.exe'

Share Improve this question asked Jun 19, 2016 at 0:33 SrcSrc 5,5426 gold badges31 silver badges61 bronze badges 2
  • 1 Do you mean to use template literals? You have to use backticks: `${__dirname}/install.exe`. '${__dirname}/install.exe' creates a string that literally contains the character sequence ${__dirname}. – Felix Kling Commented Jun 19, 2016 at 0:34
  • @FelixKling, same again.. – Src Commented Jun 19, 2016 at 0:35
Add a ment  | 

1 Answer 1

Reset to default 5

@FelixKling has the right advice; variables don't work unless you create your string with back-ticks. Additionally, it's a good idea to use the path module to resolve file paths:

var path = require('path');
var execFile = require('child_process').execFile;

var exePath = path.resolve(__dirname, './install.exe');
execFile(exePath, function(error, stderr) {
   console.log('stderr: ', __dirname);
   if (error !== null) {
       console.log('exec error: ', error);
   }
});

Edit:

This is for your original question, about ENOENT; for your second about UNKNOWN errors, the cause can vary. It sounds like it might be a permissions issue since the executable needs to elevate to administrator permissions.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744983334a4604467.html

相关推荐

  • javascript - Node.JS: execFile ENOENT - Stack Overflow

    I've tried to execute *.exe file, but got:exec error:{ Error: spawn ${__dirname}install.exe ENO

    21小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信