Newlines in arguments passed to `node -e ...`
Author: julienpCreated Jul 12, 2024Updated Apr 28, 2026
Labelsbug
We ran into an issue when calling node -e ... with a script that contains new lines. https://github.com/pulumi/pulumi/pull/16649
Repro:
main.go:
package main
import (
"fmt"
"os/exec"
)
func main() {
argWithNewLines := `if (true) {
console.log("it's true!");
}`
cmd := exec.Command("node", "-e", argWithNewLines)
out, err := cmd.Output()
if err != nil {
fmt.Printf("Error: %s", err)
}
fmt.Println(string(out))
}Run with:
go run main.goWhen I have the Volta shim node.exe in the path, I get an error:
PS C:\Users\pulumiadmin> go run main.go
Error: exit status 1With the actual node.exe on path, it works:
PS C:\Users\pulumiadmin> go run main.go
it's true!Source: volta-cli/volta