[bug-bash] Multi-statement -c and piped stdin silently drop intermediate output and file redirections
Maintainer thường phản hồi trong vòng 1 ngày
Một pull request liên quan đã được merge.
- #286 của @mkrueger — đã merge
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 75/100
Hướng nghiên cứu
Start with ShellInterpreter.RunCommandAsync and compare how it runs parsed statements with CommandStatement handling script-file execution; the issue identifies both as investigation leads. Reproduce with the provided -c commands and piped stdin, then check output and redirected files. Done when intermediate output and each redirection are preserved, including when a later command fails.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Environment
- Windows x64
- CosmosDBShell 1.1.291-preview (db49321323), installed global-tool executable
- No database connection, credentials, or customer data required
Repro (PowerShell)
Run in a fresh disposable working directory. Invoke the tested executable
explicitly to avoid an older executable on PATH:
$package = "$env:USERPROFILE\.dotnet\tools\.store\cosmosdbshell\1.1.291-preview"
$shell = Join-Path $package 'cosmosdbshell.win-x64\1.1.291-preview\tools\net10.0\win-x64\CosmosDBShell.exe'
$work = Join-Path ([IO.Path]::GetTempPath()) ("cosmos-output-" + [guid]::NewGuid().ToString("N"))
New-Item -ItemType Directory -Path $work | Out-Null
Set-Location $work
& $shell --version
& $shell --output json --quiet -c 'echo "first" > result.txt; echo "second" >> result.txt'
$code = $LASTEXITCODE
Get-Content .\result.txt
"Exit code: $code"
Expected
result.txt contains both lines, in order:
first
second
Actual
result.txt contains only:
second
The process exits 0 and stderr is empty. The failure reproduces on repeat runs
using fresh destination files.
Additional comparisons
- Separate destinations:
& $shell --output json --quiet -c 'echo "alpha" > alpha.txt; echo "beta" > beta.txt'
Actual: beta.txt exists with "beta"; alpha.txt is not created.
- No redirection:
& $shell --output json --quiet -c 'echo "first"; echo "second"'
Actual stdout: only "second".
- Piped stdin:
@'
echo "first" > stdin.txt
echo "second" >> stdin.txt
'@ | & $shell --output json --quiet
Actual: stdin.txt contains only "second".
- Earlier successful command followed by a runtime failure:
& $shell --output json --quiet -c 'echo "before" > before-error.txt; not-a-real-command'
Actual: exit 2 with a structured error, but before-error.txt is not created.
- Redirect an entire script inside the Cosmos DB Shell language:
@'
echo "first"
echo "second"
'@ | Set-Content -Encoding utf8 .\inner.csh
& $shell --output json --quiet -c 'inner.csh > whole-script.txt'
Get-Content .\whole-script.txt
Actual: whole-script.txt contains only "second". Running
inner.csh >> whole-script-append.txt against a new file preserves both lines.
This is in-shell script redirection, not operating-system redirection of the
entire CLI process.
Working controls / workaround
- Running the two commands in separate shell processes preserves both lines.
- A .csh script file containing the same two lines preserves both lines:
@'
echo "first" > script.txt
echo "second" >> script.txt
'@ | Set-Content .\repro.csh
& $shell --output json --quiet -c 'repro.csh'
Get-Content .\script.txt
Actual script.txt: "first" followed by "second".
Impact
Inline CLI automation and piped scripts can silently lose output/artifacts while
reporting success. Behavior differs from running the same statements in a script
file. This can hide logs and skip expected file creation in automation.
Investigation lead (not a verified fix)
The current source's ShellInterpreter.RunCommandAsync runs parsed statements
without rendering each intermediate state. Script-file execution in
CommandStatement renders statement results individually. This is consistent
with the observed difference; the released executable was tested directly,
and no source changes were made.
Validation scope
45 local, disconnected CLI smoke checks: 44 passed, 1 failed.
Covered arithmetic, interpolation, loops, functions, script arguments/scoping,
JSON filters, parser preflight, error envelopes, exit codes, stdin and redirection.
Nine focused follow-up invocations compared the failure against working controls.
These output-loss reproductions require no connected Cosmos DB operations.
The whole-script redirection variant was independently confirmed during
subsequent focused command testing.
- Ngôn ngữ chính
- C#
- Star
- 4
- Fork
- 7
- Merge trung bình
- 1 ngày 15 giờ
- Pull request đã merge (30 ngày)
- 33
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của Azure/CosmosDBShell
-
Connection to mcp failed?Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
Azure/CosmosDBShell#274 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
Azure/CosmosDBShell#265 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
Azure/CosmosDBShell#240 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
automation P1
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 45/100
Azure/CosmosDBShell#178 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Lightweight headless CI distribution (no MCP, LSP, interactive UI)Có thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mởautomation P1
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
Azure/CosmosDBShell#175 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của Azure/CosmosDBShell
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
BEagle1984/silverback#280 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 63/100
-
Status: Needs Triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
PSAppDeployToolkit/PSAppDeployToolkit#2392 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Playground selection bar: comes back after Apply or scrolling while focus is in the Markdown paneĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
sillsdev/SIL.TextEditing#175 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
needs attention untriaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet#3666 ·
Maintainer thường phản hồi trong vòng 3 ngày