Closed hacker-DOM closed 1 month ago
Solution (I do not know why it works):
❯ (python -c "import sys; print('{\"a\": 5}',file=sys.stderr)") 2> >(jless)
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 5, kind: Uncategorized, message: "Input/output error" }', src/main.rs:68:45
jless
))❯ (python -c "import sys; print('{\"a\": 5}',file=sys.stderr)"; echo) 2> >(jless)
Closing this in case it's not relevant, but I think the expected behavior is still that it would work even without the echo. One can test with a script
filedescriptor.py
import sys
import logging
# Configure logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(message)s')
def log_first_last_stdin():
first_line = None
last_line = None
# Read stdin line by line
for line in sys.stdin:
if first_line is None:
first_line = line.strip()
logging.info(f"First stdin line: {first_line}")
last_line = line.strip()
if last_line is not None:
logging.info(f"Last stdin line: {last_line}")
if __name__ == "__main__":
log_first_last_stdin()
that both versions yield the same stdin:
❯ (echo hi; echo '{"a": 5}' >&2) 2> >(python filedescriptors.py)
hi
2024-06-08 10:15:48,954 - First stdin line: {"a": 5}
2024-06-08 10:15:48,954 - Last stdin line: {"a": 5}
❯ python -c "import sys; print('{"a": 5}',file=sys.stderr)" 2> >(python filedescriptors.py)
2024-06-08 10:16:32,563 - First stdin line: {a: 5}
2024-06-08 10:16:32,563 - Last stdin line: {a: 5}
so it does indeed seem to be a problem in jless.
It seems to occur in these lines:
and then either:
https://github.com/redox-os/termion/blob/42491e843cfeb809b39b19f977fbb8b4cc383852/src/raw.rs#L103, or https://github.com/redox-os/termion/blob/42491e843cfeb809b39b19f977fbb8b4cc383852/src/raw.rs#L108
I'm not the best with these things so don't have much more to contribute, but logging it here fwiw.
I think the following command (zsh)
does the following:
Instead we get (RUST_BACKTRACE=full)
```zsh ❯ export RUST_BACKTRACE=full; python -c "import sys; print('{\"a\": 5}',file=sys.stderr)" 2> >(jless) thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 5, kind: Uncategorized, message: "Input/output error" }', src/main.rs:68:45 stack backtrace: 0: 0x102e10f10 -Fun fact: this does work:
(it prints hi to console and opens
jless
with the json).