#command-output #pty #tty #terminal #logging #process #exec

app faketty

Wrapper to exec a command in a pty, even if redirecting the output

17 stable releases

1.0.16 Feb 29, 2024
1.0.14 Dec 21, 2023
1.0.13 Aug 28, 2023
1.0.12 Dec 17, 2022
1.0.1 Sep 21, 2020

#55 in Command line utilities

Download history 29/week @ 2023-12-22 15/week @ 2023-12-29 11/week @ 2024-01-05 29/week @ 2024-01-12 24/week @ 2024-01-19 22/week @ 2024-01-26 17/week @ 2024-02-02 19/week @ 2024-02-09 45/week @ 2024-02-16 436/week @ 2024-02-23 137/week @ 2024-03-01 54/week @ 2024-03-08 37/week @ 2024-03-15 31/week @ 2024-03-22 46/week @ 2024-03-29 30/week @ 2024-04-05

148 downloads per month

MIT/Apache

12KB
173 lines

faketty

github crates.io build status

A wrapper binary to exec a command in a pty, even if redirecting the output.

This allows logging the stdout and stderr (separately) of a process, without the output being different from what you'd see in the terminal if you weren't logging anything.

$ cargo install faketty
$ faketty bazel build :target >log/out 2>log/err
          ~~~~~~~~~~~~~~~~~~~ command to run

Background

When redirecting stdout/err to a pipe or file, a process may detect the output is no longer going to a tty (because it has no width/height, baud rate, etc) and may change its behavior accordingly. For example many programs that involve a progress bar or colored text in a terminal disable those things when the output is not going to a terminal.

There is a script(1) command which makes it possible to redirect a command's terminal-style output by executing it inside a pseudoterminal (pty) – a bidirectional pipe that also has width, height, etc and tricks the process into thinking it is talking to a real terminal. However, script only uses a single pty, which makes it impossible to demultiplex stdout and stderr to different places.

The faketty command in this repo is similar to script --quiet --return --command '...' /dev/null except that it preserves distinct stdout and stderr streams.


License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this program by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~3.5MB
~70K SLoC