@@ -110,6 +110,8 @@ use crate::path::Path;
110110use crate :: str;
111111use crate :: sys:: pipe:: { read2, AnonPipe } ;
112112use crate :: sys:: process as imp;
113+ #[ unstable( feature = "command_access" , issue = "44434" ) ]
114+ pub use crate :: sys_common:: process:: CommandEnvs ;
113115use crate :: sys_common:: { AsInner , AsInnerMut , FromInner , IntoInner } ;
114116
115117/// Representation of a running or exited child process.
@@ -875,6 +877,98 @@ impl Command {
875877 . map ( Child :: from_inner)
876878 . and_then ( |mut p| p. wait ( ) )
877879 }
880+
881+ /// Returns the path to the program that was given to [`Command::new`].
882+ ///
883+ /// # Examples
884+ ///
885+ /// ```
886+ /// # #![feature(command_access)]
887+ /// use std::process::Command;
888+ ///
889+ /// let cmd = Command::new("echo");
890+ /// assert_eq!(cmd.get_program(), "echo");
891+ /// ```
892+ #[ unstable( feature = "command_access" , issue = "44434" ) ]
893+ pub fn get_program ( & self ) -> & OsStr {
894+ self . inner . get_program ( )
895+ }
896+
897+ /// Returns an iterator of the arguments that will be passed to the program.
898+ ///
899+ /// This does not include the path to the program as the first argument;
900+ /// it only includes the arguments specified with [`Command::arg`] and
901+ /// [`Command::args`].
902+ ///
903+ /// # Examples
904+ ///
905+ /// ```
906+ /// # #![feature(command_access)]
907+ /// use std::ffi::OsStr;
908+ /// use std::process::Command;
909+ ///
910+ /// let mut cmd = Command::new("echo");
911+ /// cmd.arg("first").arg("second");
912+ /// let args: Vec<&OsStr> = cmd.get_args().collect();
913+ /// assert_eq!(args, &["first", "second"]);
914+ /// ```
915+ #[ unstable( feature = "command_access" , issue = "44434" ) ]
916+ pub fn get_args ( & self ) -> CommandArgs < ' _ > {
917+ CommandArgs { inner : self . inner . get_args ( ) }
918+ }
919+
920+ /// Returns an iterator of the environment variables that will be set when
921+ /// the process is spawned.
922+ ///
923+ /// Each element is a tuple `(&OsStr, Option<&OsStr>)`, where the first
924+ /// value is the key, and the second is the value, which is [`None`] if
925+ /// the environment variable is to be explicitly removed.
926+ ///
927+ /// This only includes environment variables explicitly set with
928+ /// [`Command::env`], [`Command::envs`], and [`Command::env_remove`]. It
929+ /// does not include environment variables that will be inherited by the
930+ /// child process.
931+ ///
932+ /// # Examples
933+ ///
934+ /// ```
935+ /// # #![feature(command_access)]
936+ /// use std::ffi::OsStr;
937+ /// use std::process::Command;
938+ ///
939+ /// let mut cmd = Command::new("ls");
940+ /// cmd.env("TERM", "dumb").env_remove("TZ");
941+ /// let envs: Vec<(&OsStr, Option<&OsStr>)> = cmd.get_envs().collect();
942+ /// assert_eq!(envs, &[
943+ /// (OsStr::new("TERM"), Some(OsStr::new("dumb"))),
944+ /// (OsStr::new("TZ"), None)
945+ /// ]);
946+ /// ```
947+ #[ unstable( feature = "command_access" , issue = "44434" ) ]
948+ pub fn get_envs ( & self ) -> CommandEnvs < ' _ > {
949+ self . inner . get_envs ( )
950+ }
951+
952+ /// Returns the working directory for the child process.
953+ ///
954+ /// This returns [`None`] if the working directory will not be changed.
955+ ///
956+ /// # Examples
957+ ///
958+ /// ```
959+ /// # #![feature(command_access)]
960+ /// use std::path::Path;
961+ /// use std::process::Command;
962+ ///
963+ /// let mut cmd = Command::new("ls");
964+ /// assert_eq!(cmd.get_current_dir(), None);
965+ /// cmd.current_dir("/bin");
966+ /// assert_eq!(cmd.get_current_dir(), Some(Path::new("/bin")));
967+ /// ```
968+ #[ unstable( feature = "command_access" , issue = "44434" ) ]
969+ pub fn get_current_dir ( & self ) -> Option < & Path > {
970+ self . inner . get_current_dir ( )
971+ }
878972}
879973
880974#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -899,6 +993,37 @@ impl AsInnerMut<imp::Command> for Command {
899993 }
900994}
901995
996+ /// An iterator over the command arguments.
997+ ///
998+ /// This struct is created by [`Command::get_args`]. See its documentation for
999+ /// more.
1000+ #[ unstable( feature = "command_access" , issue = "44434" ) ]
1001+ #[ derive( Debug ) ]
1002+ pub struct CommandArgs < ' a > {
1003+ inner : imp:: CommandArgs < ' a > ,
1004+ }
1005+
1006+ #[ unstable( feature = "command_access" , issue = "44434" ) ]
1007+ impl < ' a > Iterator for CommandArgs < ' a > {
1008+ type Item = & ' a OsStr ;
1009+ fn next ( & mut self ) -> Option < & ' a OsStr > {
1010+ self . inner . next ( )
1011+ }
1012+ fn size_hint ( & self ) -> ( usize , Option < usize > ) {
1013+ self . inner . size_hint ( )
1014+ }
1015+ }
1016+
1017+ #[ unstable( feature = "command_access" , issue = "44434" ) ]
1018+ impl < ' a > ExactSizeIterator for CommandArgs < ' a > {
1019+ fn len ( & self ) -> usize {
1020+ self . inner . len ( )
1021+ }
1022+ fn is_empty ( & self ) -> bool {
1023+ self . inner . is_empty ( )
1024+ }
1025+ }
1026+
9021027/// The output of a finished process.
9031028///
9041029/// This is returned in a Result by either the [`output`] method of a
0 commit comments