2015-05-12 11:03:49 -07:00
|
|
|
//! Extensions to `std::process` for Windows.
|
|
|
|
|
|
2015-06-09 16:41:14 -07:00
|
|
|
#![stable(feature = "process_extensions", since = "1.2.0")]
|
2015-05-12 11:03:49 -07:00
|
|
|
|
2019-02-11 04:23:21 +09:00
|
|
|
use crate::os::windows::io::{FromRawHandle, RawHandle, AsRawHandle, IntoRawHandle};
|
|
|
|
|
use crate::process;
|
|
|
|
|
use crate::sys;
|
|
|
|
|
use crate::sys_common::{AsInnerMut, AsInner, FromInner, IntoInner};
|
2015-05-12 11:03:49 -07:00
|
|
|
|
2015-06-09 16:41:14 -07:00
|
|
|
#[stable(feature = "process_extensions", since = "1.2.0")]
|
2015-05-12 11:03:49 -07:00
|
|
|
impl FromRawHandle for process::Stdio {
|
|
|
|
|
unsafe fn from_raw_handle(handle: RawHandle) -> process::Stdio {
|
2015-06-09 16:41:14 -07:00
|
|
|
let handle = sys::handle::Handle::new(handle as *mut _);
|
2016-02-04 11:10:37 -08:00
|
|
|
let io = sys::process::Stdio::Handle(handle);
|
|
|
|
|
process::Stdio::from_inner(io)
|
2015-05-12 11:03:49 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-09 16:41:14 -07:00
|
|
|
#[stable(feature = "process_extensions", since = "1.2.0")]
|
2015-05-12 11:03:49 -07:00
|
|
|
impl AsRawHandle for process::Child {
|
|
|
|
|
fn as_raw_handle(&self) -> RawHandle {
|
|
|
|
|
self.as_inner().handle().raw() as *mut _
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-28 11:28:42 +01:00
|
|
|
#[stable(feature = "into_raw_os", since = "1.4.0")]
|
2015-07-15 23:31:24 -07:00
|
|
|
impl IntoRawHandle for process::Child {
|
|
|
|
|
fn into_raw_handle(self) -> RawHandle {
|
|
|
|
|
self.into_inner().into_handle().into_raw() as *mut _
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-09 16:41:14 -07:00
|
|
|
#[stable(feature = "process_extensions", since = "1.2.0")]
|
2015-05-12 11:03:49 -07:00
|
|
|
impl AsRawHandle for process::ChildStdin {
|
|
|
|
|
fn as_raw_handle(&self) -> RawHandle {
|
|
|
|
|
self.as_inner().handle().raw() as *mut _
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-09 16:41:14 -07:00
|
|
|
#[stable(feature = "process_extensions", since = "1.2.0")]
|
2015-05-12 11:03:49 -07:00
|
|
|
impl AsRawHandle for process::ChildStdout {
|
|
|
|
|
fn as_raw_handle(&self) -> RawHandle {
|
|
|
|
|
self.as_inner().handle().raw() as *mut _
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-09 16:41:14 -07:00
|
|
|
#[stable(feature = "process_extensions", since = "1.2.0")]
|
2015-05-12 11:03:49 -07:00
|
|
|
impl AsRawHandle for process::ChildStderr {
|
|
|
|
|
fn as_raw_handle(&self) -> RawHandle {
|
|
|
|
|
self.as_inner().handle().raw() as *mut _
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-07-15 23:31:24 -07:00
|
|
|
|
2016-09-28 11:28:42 +01:00
|
|
|
#[stable(feature = "into_raw_os", since = "1.4.0")]
|
2015-07-15 23:31:24 -07:00
|
|
|
impl IntoRawHandle for process::ChildStdin {
|
|
|
|
|
fn into_raw_handle(self) -> RawHandle {
|
|
|
|
|
self.into_inner().into_handle().into_raw() as *mut _
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-28 11:28:42 +01:00
|
|
|
#[stable(feature = "into_raw_os", since = "1.4.0")]
|
2015-07-15 23:31:24 -07:00
|
|
|
impl IntoRawHandle for process::ChildStdout {
|
|
|
|
|
fn into_raw_handle(self) -> RawHandle {
|
|
|
|
|
self.into_inner().into_handle().into_raw() as *mut _
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-28 11:28:42 +01:00
|
|
|
#[stable(feature = "into_raw_os", since = "1.4.0")]
|
2015-07-15 23:31:24 -07:00
|
|
|
impl IntoRawHandle for process::ChildStderr {
|
|
|
|
|
fn into_raw_handle(self) -> RawHandle {
|
|
|
|
|
self.into_inner().into_handle().into_raw() as *mut _
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-04-26 15:23:46 -07:00
|
|
|
|
2018-04-09 17:44:28 -07:00
|
|
|
/// Windows-specific extensions to [`process::ExitStatus`].
|
|
|
|
|
///
|
|
|
|
|
/// [`process::ExitStatus`]: ../../../../std/process/struct.ExitStatus.html
|
2016-08-11 14:08:24 -07:00
|
|
|
#[stable(feature = "exit_status_from", since = "1.12.0")]
|
2016-04-26 15:23:46 -07:00
|
|
|
pub trait ExitStatusExt {
|
|
|
|
|
/// Creates a new `ExitStatus` from the raw underlying `u32` return value of
|
|
|
|
|
/// a process.
|
2016-08-11 14:08:24 -07:00
|
|
|
#[stable(feature = "exit_status_from", since = "1.12.0")]
|
2016-04-26 15:23:46 -07:00
|
|
|
fn from_raw(raw: u32) -> Self;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-28 11:28:42 +01:00
|
|
|
#[stable(feature = "exit_status_from", since = "1.12.0")]
|
2016-04-26 15:23:46 -07:00
|
|
|
impl ExitStatusExt for process::ExitStatus {
|
|
|
|
|
fn from_raw(raw: u32) -> Self {
|
|
|
|
|
process::ExitStatus::from_inner(From::from(raw))
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-11-30 19:44:07 -05:00
|
|
|
|
2018-04-09 17:44:28 -07:00
|
|
|
/// Windows-specific extensions to the [`process::Command`] builder.
|
|
|
|
|
///
|
|
|
|
|
/// [`process::Command`]: ../../../../std/process/struct.Command.html
|
2017-01-25 15:37:20 -08:00
|
|
|
#[stable(feature = "windows_process_extensions", since = "1.16.0")]
|
2016-11-30 19:44:07 -05:00
|
|
|
pub trait CommandExt {
|
|
|
|
|
/// Sets the [process creation flags][1] to be passed to `CreateProcess`.
|
|
|
|
|
///
|
|
|
|
|
/// These will always be ORed with `CREATE_UNICODE_ENVIRONMENT`.
|
2017-04-06 12:57:40 +01:00
|
|
|
///
|
2016-11-30 19:44:07 -05:00
|
|
|
/// [1]: https://msdn.microsoft.com/en-us/library/windows/desktop/ms684863(v=vs.85).aspx
|
2017-01-25 15:37:20 -08:00
|
|
|
#[stable(feature = "windows_process_extensions", since = "1.16.0")]
|
2016-11-30 21:31:47 -05:00
|
|
|
fn creation_flags(&mut self, flags: u32) -> &mut process::Command;
|
2016-11-30 19:44:07 -05:00
|
|
|
}
|
|
|
|
|
|
2017-01-25 15:37:20 -08:00
|
|
|
#[stable(feature = "windows_process_extensions", since = "1.16.0")]
|
2016-11-30 19:44:07 -05:00
|
|
|
impl CommandExt for process::Command {
|
2016-11-30 21:31:47 -05:00
|
|
|
fn creation_flags(&mut self, flags: u32) -> &mut process::Command {
|
|
|
|
|
self.as_inner_mut().creation_flags(flags);
|
2016-11-30 19:44:07 -05:00
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
}
|