How do I detect if stdout is connected to a tty in Perl?

↘锁芯ラ 提交于 2019-11-29 05:49:59

Use the -t filetest operator.

print -t STDOUT ? "Yes\n" : "No\n"

Note that in Perl, STDOUT can be tied (essentially an overcomplicated overloaded object) so output to STDOUT may still reach a TTY even if its not directly attached to one.

Use IO::interactive if you require STDOUT to actually be connected to the terminal, and not just being redirected to /dev/null/ or whatever.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!