bacon icon indicating copy to clipboard operation
bacon copied to clipboard

`stdout` and `stderr` are sometimes interleaved

Open narpfel opened this issue 7 months ago • 3 comments

When a command produces output on both stdout and stderr, sometimes both are interleaved.

Small reproducer (with cargo new t && cd t): src/main.rs:

fn main() {
    for i in 0..10 {
        println!("stdout: {i}");
    }
    for i in 0..10 {
        eprintln!("stderr: {i}");
    }
}

bacon run:

     Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.01s
      Running `target/debug/t`
 stdout: 0
 stderr: 0
 stdout: 1
 stdout: 2
 stdout: 3
 stdout: 4
 stdout: 5
 stdout: 6
 stdout: 7
 stdout: 8
 stdout: 9
 stderr: 1
 stderr: 2
 stderr: 3
 stderr: 4
 stderr: 5
 stderr: 6
 stderr: 7
 stderr: 8
 stderr: 9

(This sometimes needs a few tries.)

This is especially noticeable when the program normally produces output on stdout and then dbg!() is used to produce additional debug output.


$ bacon --version
bacon 3.14.0

narpfel avatar May 30 '25 19:05 narpfel

Hum. I'm not sure I can even change that without introducing a costly semaphore.

Canop avatar May 31 '25 17:05 Canop

Would std::io::pipe help?

narpfel avatar May 31 '25 20:05 narpfel

Would std::io::pipe help?

I don't know. Part of the problem is we still need to know the origin (out or err) of the bytes we receive.

Canop avatar Jun 01 '25 05:06 Canop