检测stdin是PHP中的tty设备(终端)还是管道? [英] Detect if stdin is a tty device (terminal) or pipe in PHP?
本文介绍了检测stdin是PHP中的tty设备(终端)还是管道?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我写了一个php脚本.在交互读取和执行之前,我希望它在连接到tty设备(终端)的标准输入中调用时显示帮助消息,但是在以管道中的文件或流作为标准输入时调用时不显示.
I wrote a php script. I want it show help message when called with standard input connected to a tty device (terminal) before reading and executing interactively, but dont show when called with a file or stream from pipe as standard input.
有没有一种方法可以从PHP中检测到这一点?
Is there a way to detect this from PHP?
推荐答案
使用此函数同时接受文件描述符(整数)和PHP流.如果收到PHP流,它将自动尝试对其进行广播,以获取文件描述符并改为使用它.
This function accepts both a file descriptor (an integer) and a PHP stream. If it receives a PHP stream, it automatically attempts to cast it in order to obtain a file descriptor and use it instead.
这篇关于检测stdin是PHP中的tty设备(终端)还是管道?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文