Skip to main content

Module spawn

Module spawn 

Source
Expand description

Cross-platform spawning for an external program named by a bare command string — an MCP server’s command, a subprocess tool’s command, a foreman verify command’s program.

On Windows, npm installs CLIs like npx/npm/yarn/pnpm as .cmd batch shims (there is no npx.exe). CreateProcess — which std’s and tokio’s Command::new use — cannot execute a batch file directly (it fails with os error 193, “%1 is not a valid Win32 application”), and Command::new only appends .exe when searching PATH, so it never even finds npx.cmd. The canonical MCP launch (npx -y @modelcontextprotocol/ server-…) therefore fails outright on Windows. A shim must be run through cmd /C, which does its own PATHEXT resolution.

This is the bare-name analogue of car_external_agents::detection:: base_command (which routes an already-resolved .cmd/.bat path through cmd /C). Here the input is a command name, so on Windows we resolve it via PATH + PATHEXT to decide whether it is a shim before deciding how to spawn it. Off Windows this is a plain Command::new.

Functions§

program_command
Build a tokio::process::Command for program, routing a Windows .cmd/.bat shim through cmd /C. Off Windows — and for a real .exe target or an unresolvable name — the program is spawned directly. The caller appends args / cwd / env / stdio as usual.