2024 年 PHP Conference Japan

posix_ctermid

(PHP 4, PHP 5, PHP 7, PHP 8)

posix_ctermid取得控制終端的路径名稱

說明

posix_ctermid(): 字串|false

產生一個 字串,它是目前程序控制終端的路径名稱。發生錯誤時,它會設定 errno,可以使用 posix_get_last_error() 檢查。

參數

此函式沒有參數。

返回值

成功完成後,返回目前控制終端的路径名稱 字串。否則返回 false 並設定 errno,可以使用 posix_get_last_error() 進行檢查。

範例

範例 #1 posix_ctermid() 範例

此範例將顯示目前 TTY 的路徑。

<?php
echo "I am running from ".posix_ctermid();
?>

另請參閱

新增註解

使用者貢獻的註解 1 則註解

0
phpmanual at remove dot mark dot griffin dot email
8 年前
即使 shell 已重導輸出,您也可以使用以下方式直接寫入 tty(螢幕):

<?php
$h
= fopen(posix_ctermid(), "rb+");
fwrite($h, "測試直接輸出\n");
fclose($h);
?>
To Top