Don't reopen redirected standard handles on Windows #1396
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
If the calling process has redirected a standard handle (e.g.
vulkan_samples.exe sample msaa > out.log
), then reopening it will detach it from the file/pipe and connect it to the console instead. We don't want to do that.Instead, the type of the file should be tested before attaching the parent console. If it's already a disk file or a pipe, then we want to leave it alone.
Note that for PowerShell, this doesn't make
> file
work, but| Out-File file
does, and>
works in other shells like Command Prompt and MSYS2 Bash. IIRC from past investigation when I've made similar changes to other projects, it's because PowerShell closes the file handle for/SUBSYSTEM:WINDOWS
applications immediately.General Checklist:
Please ensure the following points are checked:
Note: The Samples CI runs a number of checks including:
If this PR contains framework changes:
batch
command line argument to make sure all samples still work properlySample Checklist
N/A
If your PR contains a new or modified sample, these further checks must be carried out in addition to the General Checklist: