gpt4 book ai didi

perl - 如何检测标准输出是否连接到 Perl 中的 tty?

转载 作者:行者123 更新时间:2023-12-03 21:27:10 26 4
gpt4 key购买 nike

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

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

最佳答案

使用 -t filetest operator .

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

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

关于perl - 如何检测标准输出是否连接到 Perl 中的 tty?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3517250/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com