74

I tried to write the output of the command php -i to the a file using php -i > info and received the following error:

output is not a tty

What does it mean?

I'm using git bash on Windows.

robinCTS
  • 4,407

5 Answers5

75

I found an similar topic like this. One Solution which worked for me:

Write

php.exe -i > info

instead of

php -i > info

So yust append the .exe extension to your commands and it works.

Found this solution here: https://stackoverflow.com/a/44727575/2377961

Radon8472
  • 861
  • 6
  • 7
34

If you happen to be using winpty under the hood, you have to pass the -Xallow-non-tty argument to fix this:

$ winpty python -c 'print("hello")' | grep h
stdout is not a tty

$ winpty -Xallow-non-tty python -c 'print("hello")' | grep h hello

However, if the output is mangled, the -Xplain argument will also be required:

$ 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..

DavidW
  • 103
chtenb
  • 1,935
  • 2
  • 16
  • 17
25

What worked for me, based on Peh's comments to stackoverflow.com/questions/33622087

If you use C:\Program Files\Git\bin\bash.exe instead of C:\Program Files\Git\git-bash.exe then the command works fine

4

I believe this issue is more about how Git Bash handles piping, and less about PHP, because I encountered the same symptom using Python on Windows. The currently most-voted answer does not work for me. It might work a few months later, based on this comment and a follow-up comment. But I'm impatient so I choose to use the native Windows Command Prompt and, voila, it works!

DOESN'T WORK in Git Bash

rayluo@DESKTOP-10B0N4G MINGW64 ~
$ python -c "print('hello world')" > test.txt
stdout is not a tty

WORKS in Command Prompt

(env27) C:\Users\rayluo>python -c "print('hello world')" > test.txt
(env27) C:\Users\rayluo>type test.txt
hello world
76484
  • 103
RayLuo
  • 329
1

You are redirecting you output from your terminal (tty) to a file. Therefore your output is no longer a tty.

The message makes perfect sense. However this should not be an error.

I cannot reproduce this behavior on a linux system.

michas
  • 232