Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions library/std/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1206,6 +1206,30 @@ impl Command {
pub fn get_current_dir(&self) -> Option<&Path> {
self.inner.get_current_dir()
}

/// Returns whether the environment will be cleared for the child process.
///
/// This returns `true` if [`Command::env_clear`] was called, and `false` otherwise.
/// When `true`, the child process will not inherit any environment variables from
/// its parent process.
///
/// # Examples
///
/// ```
/// #![feature(command_resolved_envs)]
/// use std::process::Command;
///
/// let mut cmd = Command::new("ls");
/// assert_eq!(cmd.get_env_clear(), false);
///
/// cmd.env_clear();
/// assert_eq!(cmd.get_env_clear(), true);
/// ```
#[must_use]
#[unstable(feature = "command_resolved_envs", issue = "149070")]
pub fn get_env_clear(&self) -> bool {
self.inner.get_env_clear()
}
}

#[stable(feature = "rust1", since = "1.0.0")]
Expand Down
4 changes: 4 additions & 0 deletions library/std/src/sys/process/motor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ impl Command {
self.env.iter()
}

pub fn get_env_clear(&self) -> bool {
self.env.does_clear()
}

pub fn get_current_dir(&self) -> Option<&Path> {
self.cwd.as_ref().map(Path::new)
}
Expand Down
4 changes: 4 additions & 0 deletions library/std/src/sys/process/uefi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ impl Command {
self.env.iter()
}

pub fn get_env_clear(&self) -> bool {
self.env.does_clear()
}

pub fn get_current_dir(&self) -> Option<&Path> {
None
}
Expand Down
4 changes: 4 additions & 0 deletions library/std/src/sys/process/unix/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,10 @@ impl Command {
self.env.iter()
}

pub fn get_env_clear(&self) -> bool {
self.env.does_clear()
}

pub fn get_current_dir(&self) -> Option<&Path> {
self.cwd.as_ref().map(|cs| Path::new(OsStr::from_bytes(cs.as_bytes())))
}
Expand Down
4 changes: 4 additions & 0 deletions library/std/src/sys/process/unsupported.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ impl Command {
self.env.iter()
}

pub fn get_env_clear(&self) -> bool {
self.env.does_clear()
}

pub fn get_current_dir(&self) -> Option<&Path> {
self.cwd.as_ref().map(|cs| Path::new(cs))
}
Expand Down
4 changes: 4 additions & 0 deletions library/std/src/sys/process/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,10 @@ impl Command {
self.env.iter()
}

pub fn get_env_clear(&self) -> bool {
self.env.does_clear()
}

pub fn get_current_dir(&self) -> Option<&Path> {
self.cwd.as_ref().map(Path::new)
}
Expand Down
Loading