Skip to main content

spawn_shell

Function spawn_shell 

Source
pub fn spawn_shell(script_cmd: &str) -> Command
Expand description

Spawn a shell command line. On Unix we go through sh -c, on Windows through cmd.exe /d /s /c — matching what npm passes in @npmcli/run-script.

On Windows, the script command line is appended with [std::os::windows::process::CommandExt::raw_arg] instead of the normal .arg() path. .arg() would run the string through Rust’s CommandLineToArgvW-oriented encoder, which wraps it in "..." and escapes interior " as \" — but cmd.exe parses command lines with a different set of rules and does not understand \", so a script like node -e "require('is-odd')(3)" arrives mangled. raw_arg hands the command line to CreateProcessW verbatim, so we control the exact bytes cmd.exe sees. We wrap the whole script in an outer pair of double quotes, which /s tells cmd.exe to strip (just those outer quotes — the rest of the string is preserved literally). This is the same trick @npmcli/run-script and node-cross-spawn use.