File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -252,6 +252,17 @@ pub trait CommandExt: Sealed {
252
252
attribute : usize ,
253
253
value : T ,
254
254
) -> & mut process:: Command ;
255
+
256
+ /// If this flag is set to `true`, each inheritable handle in the calling process is inherited by the new process.
257
+ /// If the flag is `false`, the handles are not inherited.
258
+ ///
259
+ /// The default value for this flag is `true`.
260
+ ///
261
+ /// **Note** that inherited handles have the same value and access rights as the original handles. For additional discussion of inheritable handles, see [Remarks][1].
262
+ ///
263
+ /// [1]: <https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createprocessw#remarks>
264
+ #[ unstable( feature = "windows_process_extensions_inherit_handles" , issue = "" ) ]
265
+ fn inherit_handles ( & mut self , inherit_handles : bool ) -> & mut process:: Command ;
255
266
}
256
267
257
268
#[ stable( feature = "windows_process_extensions" , since = "1.16.0" ) ]
@@ -288,6 +299,11 @@ impl CommandExt for process::Command {
288
299
self . as_inner_mut ( ) . raw_attribute ( attribute, value) ;
289
300
self
290
301
}
302
+
303
+ fn inherit_handles ( & mut self , inherit_handles : bool ) -> & mut process:: Command {
304
+ self . as_inner_mut ( ) . inherit_handles ( inherit_handles) ;
305
+ self
306
+ }
291
307
}
292
308
293
309
#[ unstable( feature = "windows_process_extensions_main_thread_handle" , issue = "96723" ) ]
Original file line number Diff line number Diff line change @@ -168,6 +168,7 @@ pub struct Command {
168
168
stderr : Option < Stdio > ,
169
169
force_quotes_enabled : bool ,
170
170
proc_thread_attributes : BTreeMap < usize , ProcThreadAttributeValue > ,
171
+ inherit_handles : bool ,
171
172
}
172
173
173
174
pub enum Stdio {
@@ -198,6 +199,7 @@ impl Command {
198
199
stderr : None ,
199
200
force_quotes_enabled : false ,
200
201
proc_thread_attributes : Default :: default ( ) ,
202
+ inherit_handles : true ,
201
203
}
202
204
}
203
205
@@ -259,6 +261,10 @@ impl Command {
259
261
) ;
260
262
}
261
263
264
+ pub fn inherit_handles ( & mut self , inherit_handles : bool ) {
265
+ self . inherit_handles = inherit_handles;
266
+ }
267
+
262
268
pub fn spawn (
263
269
& mut self ,
264
270
default : Stdio ,
@@ -294,6 +300,7 @@ impl Command {
294
300
flags |= c:: DETACHED_PROCESS | c:: CREATE_NEW_PROCESS_GROUP ;
295
301
}
296
302
303
+ let inherit_handles = self . inherit_handles as c:: BOOL ;
297
304
let ( envp, _data) = make_envp ( maybe_env) ?;
298
305
let ( dirp, _data) = make_dirp ( self . cwd . as_ref ( ) ) ?;
299
306
let mut pi = zeroed_process_information ( ) ;
@@ -362,7 +369,7 @@ impl Command {
362
369
cmd_str. as_mut_ptr ( ) ,
363
370
ptr:: null_mut ( ) ,
364
371
ptr:: null_mut ( ) ,
365
- c :: TRUE ,
372
+ inherit_handles ,
366
373
flags,
367
374
envp,
368
375
dirp,
You can’t perform that action at this time.
0 commit comments