2015-05-12 11:03:49 -07:00
|
|
|
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
|
//
|
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
|
|
//! 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
|
|
|
|
2015-07-15 23:31:24 -07:00
|
|
|
use os::windows::io::{FromRawHandle, RawHandle, AsRawHandle, IntoRawHandle};
|
2015-05-12 11:03:49 -07:00
|
|
|
use process;
|
|
|
|
|
use sys;
|
2016-11-30 19:44:07 -05:00
|
|
|
use 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
|
|
|
|
|
|
|
|
/// Windows-specific extensions to `std::process::ExitStatus`
|
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
|
|
|
|
|
|
|
|
/// Windows-specific extensions to the `std::process::Command` builder
|
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
|
|
|
|
|
}
|
|
|
|
|
}
|