plumbum icon indicating copy to clipboard operation
plumbum copied to clipboard

Piping and `run_tee` swallows output to sys.stderr of the rear end of piped commands

Open simlei opened this issue 10 months ago • 0 comments

Take the following constructs:

/tmp/test.py

import plumbum as pb

cmd = (pb.local["/tmp/producer.bash"] | pb.local["/tmp/consumer.bash"])
c,o,e = cmd.run_tee()

/tmp/producer.bash

#!/usr/bin/env bash
echo "PROD: OUT: LINE 1" >/dev/stdout
echo "PROD: OUT: LINE 2" >/dev/stdout
echo "PROD: ERR: LINE 1" >/dev/stderr
echo "PROD: ERR: LINE 2" >/dev/stderr

/tmp/consumer.bash

#!/usr/bin/env bash
while read -r line; do
    echo "STDERR: line read: $line" >/dev/stderr
    echo "STDOUT: line read: $line" >/dev/stdout
done

and execute

python /tmp/test.py The output is:

STDOUT: line read: PROD: OUT: LINE 1
STDOUT: line read: PROD: OUT: LINE 2
PROD: ERR: LINE 1
PROD: ERR: LINE 2

However, my expectation would be:

PROD: ERR: LINE 1
PROD: ERR: LINE 2
STDERR: line read: PROD: OUT: LINE 1
STDOUT: line read: PROD: OUT: LINE 1
STDERR: line read: PROD: OUT: LINE 2
STDOUT: line read: PROD: OUT: LINE 2

The STDERR: line read... outputs of the rear of the pipe are swallowed somehow.

simlei avatar Apr 16 '24 09:04 simlei