Welcome to the Linux Foundation Forum!

Trouble with Chapter 15, exec & execSync, string interpolation of process.execPath on Windows 10

The code is:

${process.execPath} -e "console.log('A'); throw Error('B')"

Due to my node.exe being located in "C:\Program Files\nodejs\node.exe", the space between Program and Files giving me the following error:

`
err Error: Command failed: C:\Program Files\nodejs\node.exe -e "console.log('A'); throw Error('B')"
'C:\Program' is not recognized as an internal or external command,
operable program or batch file.

  1. at ChildProcess.exithandler (child_process.js:308:12)
  2. at ChildProcess.emit (events.js:315:20)
  3. at maybeClose (internal/child_process.js:1048:16)
  4. at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5) {

killed: false,
code: 1,
signal: null,
cmd: C:\\Program Files\\nodejs\\node.exe -e "console.log('A'); throw Error('B')"
}
subprocess stdout:
subprocess stderr: 'C:\Program' is not recognized as an internal or external command,
operable program or batch file.
`

Wrapping ${process.execPath} with " quotes solved this issue for me on Windows 10

Comments

This discussion has been closed.

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Categories

Upcoming Training