rederr

Have you ever wanted to more easily distinguish between stderr and stdout when running a terminal command? Maybe wanted stderr to be colored red and stdout to be normal?

Well, here's a very simple C program that does that for you.

Here's how it can be download, installed, and used:

Usage

rederr --help
Usage: rederr [-h|--help] CMD [ARG] ...

    Runs CMD with stdout like this and stderr like this.

Version: 1.0.0

Environment variables:
    REDERR_STDOUT_PREFIX
        bytes to write before stdout; default: ""
    REDERR_STDOUT_SUFFIX
        bytes to write after stdout; default: ""
    REDERR_STDERR_PREFIX
        bytes to write before stderr; default: "\e[31m" (foreground red)
    REDERR_STDERR_SUFFIX
        bytes to write after stderr; default: "\e[0m" (reset)

Notes:
    CMD is launched with stdout and stderr as a pipe, not a virtual tty.

    If stderr and stdout are written close together, output may be out of order.

    rederr only adds additional output to stdout/stderr for formatting,
    if CMD emits ANSI escape codes, they will be present in the output.

    rederr exits with 111 in case of an internal errors.

Installation

Binary builds of rederr can be found at: https://abstract.properties/misc/rederr and https://abstract.properties/misc/rederr.com. Both are identical and have a SHA-256 checksum of 4047fd8848875f9441fc22bd6bb674c273d68ddd10a9d800d6cd80fdf50239bd.

These are αcτµαlly pδrταblε εxεcµταblε builds built with cosmopolitan libc, which means they are fat binary executables that run on practically any platform: Linux + Mac + Windows + FreeBSD + OpenBSD + NetBSD + BIOS on AMD64 and ARM64.

End up using this on a non-Linux/Mac/Windows platform? Please reach out and let me know.

Source Code

The source code can be found here: https://github.com/sufianrhazi/rederr

To build it yourself, run make. You can set the CC environment variable to specify your compiler of choice.

Notes

In my day to day work, I pretty much live in a commandline terminal. I think there are a whole bunch of missing small tools meant to improve the day to day quality of life if you work in the commandline.

This is one of those tools, I'll be making more.

A few things to keep in mind about rederr:

  • It is simple, all it does and will ever do is wrap chunks written to stdout / stderr with a prefix and suffix.
  • It is only configurable through environment variables.
  • It works best with programs that don't emit ANSI terminal color escape codes at all if they are not writing to a terminal.
  • If the underlying program writes data nearly simultaneously to stdout and stderr, it's possible that rederr will change the order of those writes.

Shout-out to Ben for the idea, thanks!