Skip to content

Commit 1a41c69

Browse files
committed
Add Command::get_env_clear
This addition allows an end-user to inspect whether the env clear value is set on a `Command` instance or not. Discussed in: - #149070 - rust-lang/libs-team#194
1 parent 3d461af commit 1a41c69

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

library/std/src/process.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,6 +1206,30 @@ impl Command {
12061206
pub fn get_current_dir(&self) -> Option<&Path> {
12071207
self.inner.get_current_dir()
12081208
}
1209+
1210+
/// Returns whether the environment will be cleared for the child process.
1211+
///
1212+
/// This returns `true` if [`Command::env_clear`] was called, and `false` otherwise.
1213+
/// When `true`, the child process will not inherit any environment variables from
1214+
/// its parent process.
1215+
///
1216+
/// # Examples
1217+
///
1218+
/// ```
1219+
/// #![feature(command_resolved_envs)]
1220+
/// use std::process::Command;
1221+
///
1222+
/// let mut cmd = Command::new("ls");
1223+
/// assert_eq!(cmd.get_env_clear(), false);
1224+
///
1225+
/// cmd.env_clear();
1226+
/// assert_eq!(cmd.get_env_clear(), true);
1227+
/// ```
1228+
#[must_use]
1229+
#[unstable(feature = "command_resolved_envs", issue = "149070")]
1230+
pub fn get_env_clear(&self) -> bool {
1231+
self.inner.env.does_clear()
1232+
}
12091233
}
12101234

12111235
#[stable(feature = "rust1", since = "1.0.0")]

0 commit comments

Comments
 (0)