我嘗試php -i
使用命令將命令的輸出寫入檔案php -i > info
並收到以下錯誤:
output is not a tty
這是什麼意思?
我git bash
在 Windows 上使用。
答案1
我發現了一個類似的話題。一種對我有用的解決方案:
寫
php.exe -i > info
代替
php -i > info
因此,只需將.exe
擴展名附加到您的命令中即可運行。
在這裡找到了這個解決方案:https://stackoverflow.com/a/44727575/2377961
答案2
如果您碰巧在背景使用 winpty,則必須傳遞參數-Xallow-non-tty
來解決此問題:
$ winpty python -c 'print("hello")' | grep h
stdout is not a tty
$ winpty -Xallow-non-tty python -c 'print("hello")' | grep h
hello
但是,如果輸出被破壞,則-Xplain
還需要參數:
$ winpty -Xallow-non-tty python -c 'print("hello")' | xxd
00000000: 1b5b 306d 1b5b 304b 6865 6c6c 6f1b 5b30 .[0m.[0Khello.[0
00000010: 4b1b 5b3f 3235 6c0d 0a1b 5b30 4b1b 5b3f K.[?25l...[0K.[?
00000020: 3235 68 25h
$ winpty -Xallow-non-tty -Xplain python -c 'print("hello")' | xxd
00000000: 6865 6c6c 6f0d 0a hello..
答案3
根據 Peh 對 stackoverflow.com/questions/33622087 的評論,什麼對我有用
如果您使用 C:\Program Files\Git\bin\bash.exe 而不是 C:\Program Files\Git\git-bash.exe 那麼該指令可以正常運作
答案4
您正在將終端機 (tty) 的輸出重新導向至檔案。因此你的輸出不再是一個 tty。
這個消息很有道理。然而這不應該是個錯誤。
我無法在 Linux 系統上重現此行為。