mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-21 00:00:10 +02:00
process: add arg0 method to Command (#3984)
This commit is contained in:
@@ -551,6 +551,7 @@ impl Command {
|
||||
///
|
||||
/// [1]: https://msdn.microsoft.com/en-us/library/windows/desktop/ms684863(v=vs.85).aspx
|
||||
#[cfg(windows)]
|
||||
#[cfg_attr(docsrs, doc(cfg(windows)))]
|
||||
pub fn creation_flags(&mut self, flags: u32) -> &mut Command {
|
||||
self.std.creation_flags(flags);
|
||||
self
|
||||
@@ -560,6 +561,7 @@ impl Command {
|
||||
/// `setuid` call in the child process. Failure in the `setuid`
|
||||
/// call will cause the spawn to fail.
|
||||
#[cfg(unix)]
|
||||
#[cfg_attr(docsrs, doc(cfg(unix)))]
|
||||
pub fn uid(&mut self, id: u32) -> &mut Command {
|
||||
self.std.uid(id);
|
||||
self
|
||||
@@ -568,11 +570,26 @@ impl Command {
|
||||
/// Similar to `uid` but sets the group ID of the child process. This has
|
||||
/// the same semantics as the `uid` field.
|
||||
#[cfg(unix)]
|
||||
#[cfg_attr(docsrs, doc(cfg(unix)))]
|
||||
pub fn gid(&mut self, id: u32) -> &mut Command {
|
||||
self.std.gid(id);
|
||||
self
|
||||
}
|
||||
|
||||
/// Set executable argument
|
||||
///
|
||||
/// Set the first process argument, `argv[0]`, to something other than the
|
||||
/// default executable path.
|
||||
#[cfg(unix)]
|
||||
#[cfg_attr(docsrs, doc(cfg(unix)))]
|
||||
pub fn arg0<S>(&mut self, arg: S) -> &mut Command
|
||||
where
|
||||
S: AsRef<OsStr>,
|
||||
{
|
||||
self.std.arg0(arg);
|
||||
self
|
||||
}
|
||||
|
||||
/// Schedules a closure to be run just before the `exec` function is
|
||||
/// invoked.
|
||||
///
|
||||
@@ -603,6 +620,7 @@ impl Command {
|
||||
/// working directory have successfully been changed, so output to these
|
||||
/// locations may not appear where intended.
|
||||
#[cfg(unix)]
|
||||
#[cfg_attr(docsrs, doc(cfg(unix)))]
|
||||
pub unsafe fn pre_exec<F>(&mut self, f: F) -> &mut Command
|
||||
where
|
||||
F: FnMut() -> io::Result<()> + Send + Sync + 'static,
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
#![warn(rust_2018_idioms)]
|
||||
#![cfg(all(feature = "full", unix))]
|
||||
|
||||
use tokio::process::Command;
|
||||
|
||||
#[tokio::test]
|
||||
async fn arg0() {
|
||||
let mut cmd = Command::new("sh");
|
||||
cmd.arg0("test_string").arg("-c").arg("echo $0");
|
||||
|
||||
let output = cmd.output().await.unwrap();
|
||||
assert_eq!(output.stdout, b"test_string\n");
|
||||
}
|
||||
Reference in New Issue
Block a user