如何检测标准输出是否连接到 Perl 中的 tty? [英] How do I detect if stdout is connected to a tty in Perl?

查看:41
本文介绍了如何检测标准输出是否连接到 Perl 中的 tty?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找与此 Python 代码等效的 Perl:

I'm looking for the Perl equivalent to this Python code:

from sys import stdout
if stdout.isatty():
    print "yes"
else:
    print "no"

推荐答案

使用 -t filetest运算符.

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

请注意,在 Perl 中,STDOUT 可以绑定(本质上是一个过于复杂的重载对象),因此输出到 STDOUT 的输出可能仍会到达 TTY,即使它没有直接附加到一个.

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.

这篇关于如何检测标准输出是否连接到 Perl 中的 tty?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆