Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows: CommandExt::async_pipes #97149

Merged
merged 1 commit into from
Jun 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 40 additions & 0 deletions library/std/src/os/windows/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,37 @@ pub trait CommandExt: Sealed {
/// `CommandLineToArgvW` escaping rules.
#[stable(feature = "windows_process_extensions_raw_arg", since = "1.62.0")]
fn raw_arg<S: AsRef<OsStr>>(&mut self, text_to_append_as_is: S) -> &mut process::Command;

/// When [`process::Command`] creates pipes, request that our side is always async.
///
/// By default [`process::Command`] may choose to use pipes where both ends
/// are opened for synchronous read or write operations. By using
/// `async_pipes(true)`, this behavior is overridden so that our side is
/// always async.
///
/// This is important because if doing async I/O a pipe or a file has to be
/// opened for async access.
///
/// The end of the pipe sent to the child process will always be synchronous
/// regardless of this option.
///
/// # Example
///
/// ```
m-ou-se marked this conversation as resolved.
Show resolved Hide resolved
/// #![feature(windows_process_extensions_async_pipes)]
/// use std::os::windows::process::CommandExt;
/// use std::process::{Command, Stdio};
///
/// # let program = "";
///
/// Command::new(program)
/// .async_pipes(true)
/// .stdin(Stdio::piped())
/// .stdout(Stdio::piped())
/// .stderr(Stdio::piped());
/// ```
#[unstable(feature = "windows_process_extensions_async_pipes", issue = "98289")]
fn async_pipes(&mut self, always_async: bool) -> &mut process::Command;
}

#[stable(feature = "windows_process_extensions", since = "1.16.0")]
Expand All @@ -179,6 +210,15 @@ impl CommandExt for process::Command {
self.as_inner_mut().raw_arg(raw_text.as_ref());
self
}

fn async_pipes(&mut self, always_async: bool) -> &mut process::Command {
// FIXME: This currently has an intentional no-op implementation.
// For the time being our side of the pipes will always be async.
// Once the ecosystem has adjusted, we may then be able to start making
// use of synchronous pipes within the standard library.
let _ = always_async;
self
}
}

#[unstable(feature = "windows_process_extensions_main_thread_handle", issue = "96723")]
Expand Down