如何判断 STDIN 是否连接到 Perl 中的终端? [英] How can I tell if STDIN is connected to a terminal in Perl?
本文介绍了如何判断 STDIN 是否连接到 Perl 中的终端?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何判断标准输入是否连接到 Perl 中的终端?
How can I tell if STDIN is connected to a terminal in Perl?
推荐答案
if (-t *STDIN) {
# stdin is connected
} else {
# stdin is not connected
}
我通常将它与 -t *STDOUT
结合使用,以确定我是从交互式 shell 还是从 cron 运行,以启用更多输出.
I usually use this in conjunction with -t *STDOUT
, to find out if I'm running from an interactive shell, or from cron, to enable more output.
这篇关于如何判断 STDIN 是否连接到 Perl 中的终端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文