rtk wc does not read stdin — silent false zero on redirect and pipe
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 81.1k
- Forks
- 5.1k
- Avg merge
- 4d 21h
- Merged PRs (30d)
- 35
Description
Description
rtk wc does not read stdin at all — neither via redirect (<) nor pipe (|). When no file operand is given, it prints 0 and exits 0, making it indistinguishable from a real empty file.
This is the same class as #4084 (rtk curl drops stdin body), but worse: wc is a counting instrument, and 0 is a fully plausible answer to nearly every question it gets pointed at. A false zero from wc reads as "nothing there", not as an error.
Reproduction
Each command must be alone and first in its block (see "position-dependent" note below):
# Setup
printf 'a\nb\nc\n' > /tmp/wc-test.txt
# BUG: redirect stdin — should be 3, returns 0
rtk wc -l < /tmp/wc-test.txt
# Output: 0 (rc=0)
# BUG: pipe stdin — should be 3, returns 0
printf 'a\nb\nc\n' | rtk wc -l
# Output: 0 (rc=0)
# CORRECT: file argument
rtk wc -l /tmp/wc-test.txt
# Output: 3 (rc=0)
# CORRECT: native wc
/usr/bin/wc -l < /tmp/wc-test.txt
# Output: 3 (rc=0)
Position-dependent trigger (why it looks intermittent)
rtk rewrite rewrites only the first matched command in a block. So:
wc -l < falone → rewritten → 0 (wrong)wc -l f; wc -l < f→ firstwcabsorbs the rewrite → second runs native → 75 (correct)
This means a "characterization re-run" that adds the suspect command to an existing block will defeat reproduction. The command must be isolated.
Environment
- rtk 0.38.0
- Linux 6.6.87.2 (WSL2), x86-64
Expected behavior
Either:
rtk wcshould forward stdin to nativewcwhen no file arguments are given, ORrtk wcshould exit non-zero when stdin would be needed but isn't handled
Never: print 0 with rc=0.
Workaround
We guard this in our hook (rtk-rewrite.sh) by matching on $REWRITTEN to skip rewriting standalone wc commands while preserving pipeline upstream savings (e.g., rtk ls | wc -l still works because only ls is rewritten).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the isolated redirect and pipe cases with rtk wc -l, then trace how rtk rewrite handles the first matched command and how wc handles missing file operands. Done means stdin is forwarded to native wc when no file arguments are supplied, or the command exits non-zero instead of silently printing 0; preserve the working file-operand and pipeline behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100