#![stable(feature = "rust1", since = "1.0.0")]
+use crate::ffi::OsStr;
use crate::io;
use crate::process;
use crate::sys;
/// cross-platform `spawn` instead.
#[stable(feature = "process_exec2", since = "1.9.0")]
fn exec(&mut self) -> io::Error;
+
+ /// Set executable argument
+ ///
+ /// Set the first process argument, `argv[0]`, to something other than the
+ /// default executable path.
+ #[unstable(feature = "process_set_argv0", issue = "66510")]
+ fn arg0<S>(&mut self, arg: S) -> &mut process::Command
+ where
+ S: AsRef<OsStr>;
}
#[stable(feature = "rust1", since = "1.0.0")]
fn exec(&mut self) -> io::Error {
self.as_inner_mut().exec(sys::process::Stdio::Inherit)
}
+
+ fn arg0<S>(&mut self, arg: S) -> &mut process::Command
+ where
+ S: AsRef<OsStr>,
+ {
+ self.as_inner_mut().set_arg_0(arg.as_ref());
+ self
+ }
}
/// Unix-specific extensions to [`process::ExitStatus`].
let program = os2c(program, &mut saw_nul);
Command {
argv: Argv(vec![program.as_ptr(), ptr::null()]),
+ args: vec![program.clone()],
program,
- args: Vec::new(),
env: Default::default(),
cwd: None,
uid: None,
}
}
+ pub fn set_arg_0(&mut self, arg: &OsStr) {
+ // Set a new arg0
+ let arg = os2c(arg, &mut self.saw_nul);
+ debug_assert!(self.argv.0.len() > 1);
+ self.argv.0[0] = arg.as_ptr();
+ self.args[0] = arg;
+ }
+
pub fn arg(&mut self, arg: &OsStr) {
// Overwrite the trailing NULL pointer in `argv` and then add a new null
// pointer.
let arg = os2c(arg, &mut self.saw_nul);
- self.argv.0[self.args.len() + 1] = arg.as_ptr();
+ self.argv.0[self.args.len()] = arg.as_ptr();
self.argv.0.push(ptr::null());
// Also make sure we keep track of the owned value to schedule a
&self.argv.0
}
+ pub fn get_program(&self) -> &CStr {
+ &*self.program
+ }
+
#[allow(dead_code)]
pub fn get_cwd(&self) -> &Option<CString> {
&self.cwd
impl fmt::Debug for Command {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- write!(f, "{:?}", self.program)?;
- for arg in &self.args {
+ if self.program != self.args[0] {
+ write!(f, "[{:?}] ", self.program)?;
+ }
+ write!(f, "{:?}", self.args[0])?;
+
+ for arg in &self.args[1..] {
write!(f, " {:?}", arg)?;
}
Ok(())
let _lock = sys::os::env_lock();
let ret = libc::rtpSpawn(
- self.get_argv()[0], // executing program
+ self.get_program().as_ptr(),
self.get_argv().as_ptr() as *mut *const c_char, // argv
c_envp as *mut *const c_char,
100 as c_int, // initial priority