]>
Commit | Line | Data |
---|---|---|
62682a34 SL |
1 | // Copyright 2015 The Rust Project Developers. See the COPYRIGHT |
2 | // file at the top-level directory of this distribution and at | |
3 | // http://rust-lang.org/COPYRIGHT. | |
4 | // | |
5 | // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | |
6 | // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | |
7 | // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | |
8 | // option. This file may not be copied, modified, or distributed | |
9 | // except according to those terms. | |
10 | ||
11 | //! Extensions to `std::process` for Windows. | |
12 | ||
13 | #![stable(feature = "process_extensions", since = "1.2.0")] | |
14 | ||
c1a9b12d | 15 | use os::windows::io::{FromRawHandle, RawHandle, AsRawHandle, IntoRawHandle}; |
62682a34 SL |
16 | use process; |
17 | use sys; | |
476ff2be | 18 | use sys_common::{AsInnerMut, AsInner, FromInner, IntoInner}; |
62682a34 SL |
19 | |
20 | #[stable(feature = "process_extensions", since = "1.2.0")] | |
21 | impl FromRawHandle for process::Stdio { | |
22 | unsafe fn from_raw_handle(handle: RawHandle) -> process::Stdio { | |
23 | let handle = sys::handle::Handle::new(handle as *mut _); | |
7453a54e SL |
24 | let io = sys::process::Stdio::Handle(handle); |
25 | process::Stdio::from_inner(io) | |
62682a34 SL |
26 | } |
27 | } | |
28 | ||
29 | #[stable(feature = "process_extensions", since = "1.2.0")] | |
30 | impl AsRawHandle for process::Child { | |
31 | fn as_raw_handle(&self) -> RawHandle { | |
32 | self.as_inner().handle().raw() as *mut _ | |
33 | } | |
34 | } | |
35 | ||
c30ab7b3 | 36 | #[stable(feature = "into_raw_os", since = "1.4.0")] |
c1a9b12d SL |
37 | impl IntoRawHandle for process::Child { |
38 | fn into_raw_handle(self) -> RawHandle { | |
39 | self.into_inner().into_handle().into_raw() as *mut _ | |
40 | } | |
41 | } | |
42 | ||
62682a34 SL |
43 | #[stable(feature = "process_extensions", since = "1.2.0")] |
44 | impl AsRawHandle for process::ChildStdin { | |
45 | fn as_raw_handle(&self) -> RawHandle { | |
46 | self.as_inner().handle().raw() as *mut _ | |
47 | } | |
48 | } | |
49 | ||
50 | #[stable(feature = "process_extensions", since = "1.2.0")] | |
51 | impl AsRawHandle for process::ChildStdout { | |
52 | fn as_raw_handle(&self) -> RawHandle { | |
53 | self.as_inner().handle().raw() as *mut _ | |
54 | } | |
55 | } | |
56 | ||
57 | #[stable(feature = "process_extensions", since = "1.2.0")] | |
58 | impl AsRawHandle for process::ChildStderr { | |
59 | fn as_raw_handle(&self) -> RawHandle { | |
60 | self.as_inner().handle().raw() as *mut _ | |
61 | } | |
62 | } | |
c1a9b12d | 63 | |
c30ab7b3 | 64 | #[stable(feature = "into_raw_os", since = "1.4.0")] |
c1a9b12d SL |
65 | impl IntoRawHandle for process::ChildStdin { |
66 | fn into_raw_handle(self) -> RawHandle { | |
67 | self.into_inner().into_handle().into_raw() as *mut _ | |
68 | } | |
69 | } | |
70 | ||
c30ab7b3 | 71 | #[stable(feature = "into_raw_os", since = "1.4.0")] |
c1a9b12d SL |
72 | impl IntoRawHandle for process::ChildStdout { |
73 | fn into_raw_handle(self) -> RawHandle { | |
74 | self.into_inner().into_handle().into_raw() as *mut _ | |
75 | } | |
76 | } | |
77 | ||
c30ab7b3 | 78 | #[stable(feature = "into_raw_os", since = "1.4.0")] |
c1a9b12d SL |
79 | impl IntoRawHandle for process::ChildStderr { |
80 | fn into_raw_handle(self) -> RawHandle { | |
81 | self.into_inner().into_handle().into_raw() as *mut _ | |
82 | } | |
83 | } | |
a7813a04 XL |
84 | |
85 | /// Windows-specific extensions to `std::process::ExitStatus` | |
5bcae85e | 86 | #[stable(feature = "exit_status_from", since = "1.12.0")] |
a7813a04 XL |
87 | pub trait ExitStatusExt { |
88 | /// Creates a new `ExitStatus` from the raw underlying `u32` return value of | |
89 | /// a process. | |
5bcae85e | 90 | #[stable(feature = "exit_status_from", since = "1.12.0")] |
a7813a04 XL |
91 | fn from_raw(raw: u32) -> Self; |
92 | } | |
93 | ||
c30ab7b3 | 94 | #[stable(feature = "exit_status_from", since = "1.12.0")] |
a7813a04 XL |
95 | impl ExitStatusExt for process::ExitStatus { |
96 | fn from_raw(raw: u32) -> Self { | |
97 | process::ExitStatus::from_inner(From::from(raw)) | |
98 | } | |
99 | } | |
476ff2be SL |
100 | |
101 | /// Windows-specific extensions to the `std::process::Command` builder | |
102 | #[unstable(feature = "windows_process_extensions", issue = "37827")] | |
103 | pub trait CommandExt { | |
104 | /// Sets the [process creation flags][1] to be passed to `CreateProcess`. | |
105 | /// | |
106 | /// These will always be ORed with `CREATE_UNICODE_ENVIRONMENT`. | |
107 | /// [1]: https://msdn.microsoft.com/en-us/library/windows/desktop/ms684863(v=vs.85).aspx | |
108 | #[unstable(feature = "windows_process_extensions", issue = "37827")] | |
109 | fn creation_flags(&mut self, flags: u32) -> &mut process::Command; | |
110 | } | |
111 | ||
112 | #[unstable(feature = "windows_process_extensions", issue = "37827")] | |
113 | impl CommandExt for process::Command { | |
114 | fn creation_flags(&mut self, flags: u32) -> &mut process::Command { | |
115 | self.as_inner_mut().creation_flags(flags); | |
116 | self | |
117 | } | |
118 | } |