Open ilyvion opened 1 month ago
Ooh, I should add that there's a comment in the issue I linked that says
If some of you weren't aware, it might help to know that the
which
crate has logic for handling this without requiring you to append.cmd
,.com
,.bat
,.exe
, etc. This is based on thePATHEXT
environment variable on Windows, which you don't have to set it yourself.Hope that helps others like it helped me!
Which means that there's a Rust-ier solution than having to invoke cmd
that should work on any OS:
let result = which("rustc").unwrap();
assert_eq!(result, PathBuf::from("/usr/bin/rustc"));
👍
Thanks to rust-lang/rust#37519,
Command::spawn
expects a command to have an.exe
extension, but on Windows, a bunch of executable files have other endings, like.bat
or.cmd
, which causes me trouble when usingcargo-leptos
:The reason this doesn't work is because
npx
on my system is annpx.cmd
file:and
Command::spawn
won't find it, even though the command itself works just fine when run in a shell:One of the ways to work around this is to preface the command with something like
cmd /C
on Windows, which runs it through thecmd
shell, which knows how to handle those other file types:This can be fairly easily added to a
Command::spawn
invocation.