Skip to content

Only read stdin when no files are given, or when a flag asks for it #736

Closed

Description

@mathiasrw

Today

RexReplace reads stdin every time stdin is not a terminal, also when files are given. It waits for stdin to close before it starts.

Some environments (CI runners, agent harnesses, cron, docker exec) give the process a pipe that is open, but never written to and never closed. Then RexReplace hangs:

> sleep 3 | grep foo a.txt                 # done at once
> sleep 3 | rexreplace foo bar a.txt -o    # waits 3 seconds

grep, sed, awk and jq do not hang, as they only read stdin when no file is given.

Change

Only read stdin when it is asked for:

When The piped data is
No files are given The content
--replacement-pipe (-R) The replacement
--pipe (-p) Given to the JavaScript in pipe

In all other cases stdin is not touched, so the run starts at once.

  • Add --pipe (-p): read the piped data and make it available to the JavaScript of --replacement-js as pipe. The warning that piped data is not used stays.
  • Add --js-pipe as a shorthand for --replacement-js --pipe (-jp).
  • Remove -P, --void-pipe and RR_VOID_PIPE.
  • Remove the note about the hang from the README.
> rexreplace foo bar '*.md'                          # stdin is not read
> cat names.txt | rexreplace foo bar '*.md' -R       # replacement from stdin
> cat list.txt | rexreplace x 'pipe' '*.md' --js-pipe # code gets the piped data

Good to know

  • -P and RR_VOID_PIPE were never released (npm has v7.1.14), so removing them breaks nothing.
  • No timeout: a slow writer and a writer that never writes look the same until the pipe closes.

Activity

  1. changed the title [-]Only read stdin when no files are given or with --replacement-pipe[/-] [+]Only read stdin when no files are given, or when a flag asks for it[/+] on Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions