diff options
| author | Kornel <kornel@geekhood.net> | 2025-01-06 23:39:53 +0000 |
|---|---|---|
| committer | Kornel <kornel@geekhood.net> | 2025-01-06 23:39:53 +0000 |
| commit | 85a71ea0c781920a25cc5945f21f72c40334cc77 (patch) | |
| tree | 4f6b79c3f84e65c1c0989e5673495bf26a73415d | |
| parent | 243d2ca4db6f96d2d18aaf3a2381251d38eb6b0b (diff) | |
| download | rust-85a71ea0c781920a25cc5945f21f72c40334cc77.tar.gz rust-85a71ea0c781920a25cc5945f21f72c40334cc77.zip | |
More compelling env_clear() examples
| -rw-r--r-- | library/std/src/process.rs | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/library/std/src/process.rs b/library/std/src/process.rs index 929d2b57afe..c87d4d01f29 100644 --- a/library/std/src/process.rs +++ b/library/std/src/process.rs @@ -868,13 +868,17 @@ impl Command { /// /// # Examples /// + /// Prevent any inherited `GIT_DIR` variable from changing the target of the `git` command, + /// while allowing all other variables, like `GIT_AUTHOR_NAME`. + /// /// ```no_run /// use std::process::Command; /// - /// Command::new("ls") - /// .env_remove("PATH") - /// .spawn() - /// .expect("ls command failed to start"); + /// Command::new("git") + /// .arg("commit") + /// .env_remove("GIT_DIR") + /// .spawn()?; + /// # std::io::Result::Ok(()) /// ``` #[stable(feature = "process", since = "1.0.0")] pub fn env_remove<K: AsRef<OsStr>>(&mut self, key: K) -> &mut Command { @@ -896,13 +900,17 @@ impl Command { /// /// # Examples /// + /// The behavior of `sort` is affected by `LANG` and `LC_*` environment variables. + /// Clearing the environment makes `sort`'s behavior independent of the parent processes' language. + /// /// ```no_run /// use std::process::Command; /// - /// Command::new("ls") + /// Command::new("sort") + /// .arg("file.txt") /// .env_clear() - /// .spawn() - /// .expect("ls command failed to start"); + /// .spawn()?; + /// # std::io::Result::Ok(()) /// ``` #[stable(feature = "process", since = "1.0.0")] pub fn env_clear(&mut self) -> &mut Command { |
