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'
@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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.