我是否可以确定是否从终端运行Perl脚本? [英] Can I detect if a Perl script is being run from a terminal for sure?

查看:88
本文介绍了我是否可以确定是否从终端运行Perl脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以确定是否从终端运行Perl脚本吗?

Can I detect if a Perl script is being run from a terminal for sure?

如果不确定,我宁愿默认假定它是从浏览器运行的.但是,如果有办法确保它已经从终端运行了100%,我会很高兴(出于调试目的).

I'd rather default to assume that it's been run from a browser if I'm not sure. But if there's a way to be sure that it has 100% been run from a terminal I would be happy (for debugging purposes).

非常感谢

推荐答案

使用文件测试运算符-t ,用于测试文件句柄是否已附加到终端.例如:

Use the file test operator -t which tests whether a file handle is attached to a terminal. For example:

if (-t STDIN) {
  print "Running with a terminal as input."
}

这篇关于我是否可以确定是否从终端运行Perl脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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