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

标签 perl stdout tty

我正在寻找与此 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/

相关文章:

python - 为什么 jsmin 在 python 子进程中运行时会提前退出?

linux - 在启动时启动 tty.js

perl - 如何从 Moose 获取结构化异常?

regex - Perl中正则表达式中的&号有什么用

mysql - 带线程的 Perl 邮件队列 'out of memory'

c - 在C中按 "Ctrl + c"时退出读监听

linux - 在 Perl 中将内存大小(人类可读)转换为实际数字(字节)

go - 如何清除在 Golang 的 exec.Command 中设置为 StdOut 的 bytes.Buffer(b.Reset 不起作用)

linux - 在 tty1 而不是 ttyS1 上显示 Linux 引导消息

linux - 在 Linux 中以编程方式断开并重新连接 ttyUSB0