Spawning processes in a portable way in Rust
I’m working on a command-line tool named tool-new-release
that automates the release process for the Ember Core Learning Team. It is written in Rust for reasons that I mentioned in “Automating Ember releases with Rust”.
Part of automating the release involves calling the heroku-cli
, which I do using std::process::Command
. I ran into a small stumbling block, however. Calling the executable directly with std::process:Command
was not working when on Windows. So, instead of this:
Comand::new("heroku").arg("auth:whoami");
I had to do this on Windows:
Command::new("cmd").args(&["/C", "heroku", "auth:whoami");
As you can imagine, this raised a bit of a problem. At first I using the cfg
macro and two different functions:
pub fn get_env_vars(project: &str) -> Vec<(String, String)> {
if cfg!(windows) {
check_heroku_cli_windows();
} else {
check_heroku_cli();
}
...