Reputation: 5502
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'
Upvotes: 0
Views: 6342
Reputation: 78910
@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.
Upvotes: 5