本文介绍了我是否可以确定是否从终端运行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脚本?
发布评论