是否有跨平台的方法来检查 stdout 是否正在通过管道传输到 Rust 中的另一个程序中? [英] Is there a cross-platform way to check if stdout is being piped into another program in Rust?
本文介绍了是否有跨平台的方法来检查 stdout 是否正在通过管道传输到 Rust 中的另一个程序中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当输出通过管道传输到终端以外的其他地方时,我想禁用颜色.
解决方案
翻译成 POSIX 语言,你的问题是:is stdout not a TTY",所以在 *nix 上的答案可以通过 !isatty(STDOUT_FILENO)
.libc crate 可用于从 Rust 调用它.
在 Windows 上,它很复杂,所以最好使用 atty 板条箱.>
I'd like to disable colors when the output is piped somewhere else than a terminal.
解决方案
Translated into the POSIX language, your question would be: "is stdout not a TTY", so the answer on *nix can be obtained by !isatty(STDOUT_FILENO)
. The libc crate can be used to call this from Rust.
On Windows, it's complicated, so you're better off using the atty crate.
这篇关于是否有跨平台的方法来检查 stdout 是否正在通过管道传输到 Rust 中的另一个程序中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文