Repository navigation
Preserve output of every statement in multi-statement input - #286
Conversation
Multi-statement -c/-k commands and piped stdin now render each statement's result and honor its redirections in order, like separately typed statements. Whole-script '>' redirection truncates once and keeps all script output. Fixes #277 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
Output redirection to a missing directory suppresses the I/O error diagnostic, leaving a nonzero exit without console or machine-readable error output, even when stderr is redirected.
1 open issue
What changed in this PR
Fixes #277 by preserving intermediate output and file redirections in multi-statement shell input, aligning inline and piped execution with script-file behavior.
Changes:
- Render successful top-level statements in order, scope redirections per statement, and suppress cancelled partial results.
- Truncate whole-script
>destinations once, then append subsequent statement output. - Add regression tests and document output ordering and redirection semantics.
| File | Description |
|---|---|
| docs/programming.md | Documents multi-statement output and whole-script redirection. |
| CosmosDBShell/Azure.Data.Cosmos.Shell.Parser/Statement/CommandStatement.cs | Preserves successive results when redirecting an entire script. |
| CosmosDBShell/Azure.Data.Cosmos.Shell.Core/ShellInterpreter.cs | Adds per-statement rendering and redirection restoration. |
| CosmosDBShell.Tests/UtilTest/StartupOptionTests.cs | Tests suppression of partial results after interactive cancellation. |
| CosmosDBShell.Tests/Integration/ShellProcessTests.cs | Tests output ordering, redirection scoping, failures, and script output. |
| CHANGELOG.md | Records the user-visible output preservation fix. |
Review effort: Balanced
Code coverage overviewLanguages: C# C# / code-coverage/dotnet
View coverage of the 3 most impacted files.
ℹ️ Calculations represent line coverage. Results may change as calculations are updated. Updated |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
Empty script invocations can duplicate prior output or write stale results to redirected files, and eager truncation causes an existing regression test to fail with an uncaught exception.
2 open issues
1 resolved since last review
Review effort: Balanced
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🔵 Needs a closer look
Shared output-state changes have subtle side effects on auxiliary-file overwrite behavior and empty-function result rendering that require human assessment.
No open issues 🎉
2 resolved since last review
Review effort: Balanced
…286 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>


Fixes #277.
Problem
Multi-statement
-c/-kcommands and piped stdin only rendered the final statement's result, so earlier output and file redirections were silently dropped (including output before a later runtime failure). Redirecting a whole script withscript.csh > filekept only the last result because every rendered statement reopened the file in overwrite mode.Changes
ShellInterpreter.RunCommandAsyncgains an opt-inrenderOutputmode used by the top-levelExecuteCommandCoreAsyncpath. Each successful statement is rendered in order, and redirections are restored between statements so they stay scoped to their own statement. Internal callers keep the existing final-result-only behavior.CommandStatement.RunScriptAsync: an explicit>on a script invocation truncates the destination once (after successful parse) and appends every statement's output;>>never truncates. Unwritable destinations return an error state instead of throwing.docs/programming.md) and changelog updated.Behavior notes
script.csh > filenow creates/emptiesfileeven when the script produces no output, matching usual>semantics.echo x > otherinside a script invoked with an outer>is still written to the outer destination (pre-existing behavior, out of scope).Validation
>/>>/2>scoping, earlier output before runtime failure, parse-failure no-op, pipelines/expressions not duplicated, and whole-script>/>>with blocks, functions andreturn.dotnet buildapp + tests; offline suite: 5,095 passed, 6 skipped.