I am try to testing out version check and other things with Rust std::process::command.
Other command are working fine but when I try to call npm -v, I got program not found error.
My Error:

My Code:

NPM Test:

I want to npm -v command runnable with rust
The issue is that
npmisn't justnpm, there's actually multiple (scripts):npmnpm.cmdnpm.ps1When you execute
npmin your terminal, then your terminal is smart and automatically picks the one it recognizes. In the same way that if you (on Windows) executefooit will automatically runfoo.exe.However,
Command::new()does not take this into account. So when it tries to locatenpmit ends up withnpm(sh script) and notnpm.cmd.You can resolve your issue by changing
"npm"to"npm.cmd". To have it be a bit more flexible for other operating systems, then you can use a function like this:Then you simply replace your
Command::new("npm")withnpm().Example: