execa: Subprocess should emit error if executable path doesn't exist in Windows
Returned from execa
subprocess should emit ‘error’ event if executable path doesn’t exist in Windows. Just like spawn
and execFile
in child_process
Consider this code:
const { spawn } = require('child_process')
const execa = require('execa')
const p1 = spawn('wrong-path')
p1.on('error', err => {
console.log(err) // logs ENONENT error
})
const p2 = execa('wrong-path')
p2.on('error', err => {
console.log(err) // never called in Windows, but called in Linux
})
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 15
I’m very grateful for this detailed write-up. Thank you, @ehmicky ❤️ !
Yeah, I’ve wanted to use
execa
to run GUI application and only check if it launched successfully (e.g. path to a binary file exists) and don’t wait for it to exit since it may take a long time.Previously I’ve used
child_process.spawn
withon('error')
event listener but now I’ve discovered thatspawn
doesn’t emit this event for startup failures (e.g. subprocess exits with acode 1
). So usingexeca
withPromise.race
seems like a more reliable solution and I’m pretty happy about itRunning with cmd in CI. Same result:
I’m using
cmd.exe