fix(stdlib_system): use STARTUPINFO for windows stdin redirection #1079
+79
−37
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.
Problem:-
The previous implementation attempted to redirect standard input by appending the shell operator
< filenamedirectly to the command string(e.g., cmd < input.txt).The Problem: The Windows API function CreateProcess does not spawn a shell (like cmd.exe). Consequently, it does not recognize or interpret shell operators.
The Result: The < character and the filename were passed as literal arguments to the child program. This caused the child program to receive "garbage" arguments while the actual stdin stream remained unassigned.
Solution:-
Removed Incorrect Syntax: The code no longer appends
< filenameto the command line string.Native Handle Management: Utilizes CreateFile to open a legitimate, read-only handle to the specified input file (or NUL if no file is provided).
Process Inheritance: The handle is assigned to the hStdInput field of the STARTUPINFO structure.
The STARTF_USESTDHANDLES flag is enabled to instruct the OS to use the provided handles.
Resource Cleanup: Proper logic was added to ensure the file handle is closed safely after the process is launched, preventing resource leaks.