about summary refs log tree commit diff
path: root/library/std/src/process.rs
diff options
context:
space:
mode:
authorJacob Pratt <jacob@jhpratt.dev>2025-01-08 00:52:48 -0500
committerGitHub <noreply@github.com>2025-01-08 00:52:48 -0500
commit5fa7c6a97aeca1fe7ad78caae7f4fdf680ce029d (patch)
treef3a6551cb65e1669d1f640fa5ab7b26f0a140cae /library/std/src/process.rs
parenta00bd69652340e3623feecfc1409a48d39852712 (diff)
parent85a71ea0c781920a25cc5945f21f72c40334cc77 (diff)
downloadrust-5fa7c6a97aeca1fe7ad78caae7f4fdf680ce029d.tar.gz
rust-5fa7c6a97aeca1fe7ad78caae7f4fdf680ce029d.zip
Rollup merge of #135176 - kornelski:env-example, r=cuviper
More compelling env_clear() examples

`ls` isn't a command that people usually set env vars for, and `PATH` in particular isn't even used by `ls`.
Diffstat (limited to 'library/std/src/process.rs')
-rw-r--r--library/std/src/process.rs22
1 files changed, 15 insertions, 7 deletions
diff --git a/library/std/src/process.rs b/library/std/src/process.rs
index 4ad31dfd935..e0dd2e14817 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 {