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

Commits related to this issue

Most upvoted comments

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 with on('error') event listener but now I’ve discovered that spawn doesn’t emit this event for startup failures (e.g. subprocess exits with a code 1). So using execa with Promise.race seems like a more reliable solution and I’m pretty happy about it

Running with cmd in CI. Same result:

asd

I’m using cmd.exe