php - 检测 stdin 是 PHP 中的 tty 设备(终端)还是管道?

标签 php file stdin pipe tty

我写了一个 php 脚本。我希望它在以交互方式读取和执行之前使用连接到 tty 设备(终端)的标准输入调用时显示帮助消息,但是当使用文件或来自管道的流作为标准输入调用时不显示帮助消息。

有没有办法从 PHP 检测到这个?

最佳答案

使用posix_isatty .

此函数接受文件描述符(整数)和 PHP 流。如果它接收到 PHP 流,它会自动尝试 cast it以获得文件描述符并使用它。

关于php - 检测 stdin 是 PHP 中的 tty 设备(终端)还是管道?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3648863/

相关文章:

PHP foreach,查询中使用的数组数据

c - 在 C 中读取和检查文件的内容

java - 获取 FileNotFoundException

Windows PowerShell : How to do standard-in redirection & passing parameters to commands properly?

java - 使用 Java 中的标准输入/输出与 C 程序通信

php - Soap 错误解析模式 : can't import schema from unexpected targetNamespace

php - 从mysql中的表中获取最大值

php - 将结果合并到一个数组中

C编程指针数组读取文件

dart - 在 vs code 中哪里获取用户输入?使用 Dart