Skip to content

Commit 1f4ba49

Browse files
committed
set c::STARTF_USESTDHANDLES when PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE
1 parent 08c2a0c commit 1f4ba49

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

library/std/src/sys/pal/windows/process.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -354,12 +354,21 @@ impl Command {
354354

355355
let mut si = zeroed_startupinfo();
356356

357+
// if STARTF_USESTDHANDLES is not used with PSEUDOCONSOLE,
358+
// it is not guaranteed that all the desired stdio of the new process are
359+
// really connected to the new console.
360+
// The problem + solution is described here:
361+
// https://github.com/microsoft/terminal/issues/4380#issuecomment-580865346
362+
const PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE: usize = 0x20016;
363+
let force_use_std_handles =
364+
self.proc_thread_attributes.contains_key(&PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE);
365+
357366
// If at least one of stdin, stdout or stderr are set (i.e. are non null)
358367
// then set the `hStd` fields in `STARTUPINFO`.
359368
// Otherwise skip this and allow the OS to apply its default behavior.
360369
// This provides more consistent behavior between Win7 and Win8+.
361370
let is_set = |stdio: &Handle| !stdio.as_raw_handle().is_null();
362-
if is_set(&stderr) || is_set(&stdout) || is_set(&stdin) {
371+
if force_use_std_handles || is_set(&stderr) || is_set(&stdout) || is_set(&stdin) {
363372
si.dwFlags |= c::STARTF_USESTDHANDLES;
364373
si.hStdInput = stdin.as_raw_handle();
365374
si.hStdOutput = stdout.as_raw_handle();

0 commit comments

Comments
 (0)