CLI: Make image save output optional#40194
Open
AmelBawa-msft wants to merge 4 commits intofeature/wsl-for-appsfrom
Open
CLI: Make image save output optional#40194AmelBawa-msft wants to merge 4 commits intofeature/wsl-for-appsfrom
AmelBawa-msft wants to merge 4 commits intofeature/wsl-for-appsfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds support for wslc image save to write the image archive to stdout when --output/-o is omitted, enabling shell redirection scenarios (while blocking direct writes to an interactive terminal).
Changes:
- Make
image save’s--outputargument optional and route output to stdout when omitted. - Add a terminal-safety check to reject saving directly to an interactive console without redirection.
- Extend E2E test coverage to validate stdout-save success and terminal-save failure.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| test/windows/wslc/e2e/WSLCExecutor.h | Declares a new test helper to run wslc with stdout optionally redirected to a file. |
| test/windows/wslc/e2e/WSLCExecutor.cpp | Implements the redirecting helper used by new stdout-save tests. |
| test/windows/wslc/e2e/WSLCE2EImageSaveTests.cpp | Updates tests for optional output, adds stdout-save and terminal-failure scenarios. |
| src/windows/wslc/tasks/ImageTasks.cpp | Implements image save behavior: use --output if provided, otherwise write to stdout (with terminal guard). |
| src/windows/wslc/services/ImageService.h | Adds an overload to save to a provided output HANDLE. |
| src/windows/wslc/services/ImageService.cpp | Implements the new handle-based save overload and reuses it from the path-based save. |
| src/windows/wslc/commands/ImageSaveCommand.cpp | Makes the --output argument optional at the command-definition level. |
| localization/strings/en-US/Resources.resw | Adds a localized user-facing error string for “stdout is a terminal” rejection. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
AmelBawa-msft
commented
Apr 15, 2026
- Open CONOUT$ as child stdout in RunWslcAndRedirectToFile when no output path is given, so IsConsoleHandle() returns true in the child process regardless of how CI redirects the test runner's stdout - Fix SavedArchivePath.wstring() -> SavedArchivePath in WSLCE2E_Image_Save_ToStdout_Load - Quote output path in effectiveCommandLine for diagnostic clarity Agent-Logs-Url: https://github.com/microsoft/WSL/sessions/f94556e1-9acd-40f1-89bd-349e238e92f3 Co-authored-by: AmelBawa-msft <104940545+AmelBawa-msft@users.noreply.github.com>
OneBlue
approved these changes
Apr 16, 2026
| } | ||
| else | ||
| { | ||
| // Open CONOUT$ so the child process receives a real console handle regardless of |
Collaborator
There was a problem hiding this comment.
That's clever ! I think this should be OK in most cases, but this might fail if the tests are run in a console-less context.
If that happens, we can always revisit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary of the Pull Request
PR Checklist
Detailed Description of the Pull Request / Additional comments
Validation Steps Performed