62

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,327
  • 4
  • 20
  • 29
Max Koretskyi
  • 733
  • 1
  • 5
  • 10
  • Which version of php are you using? Did the command create the info file correctly? – michas Dec 10 '15 at 08:56
  • I'm using php 7.0.0, the command created empty info file – Max Koretskyi Dec 10 '15 at 09:26
  • Hmm.. In the directory you are running the command, is there a file or directory called "info" already ? –  Dec 10 '15 at 08:41
  • no, but after running the command it is created, only empty and the error is outputted – Max Koretskyi Dec 10 '15 at 08:43
  • Please try an "strace php -i > info" then post the output here.. –  Dec 10 '15 at 08:45
  • @gerhardd., it created the info file with lots of content inside. No output to terminal. What output do you need? – Max Koretskyi Dec 10 '15 at 09:25
  • 1
    I don't have the time right now to write up an answer for this, but if any answerer wants to take the likes of https://code.google.com/p/mintty/issues/detail?id=56, http://homepage.ntlworld.com./jonathan.deboynepollard/FGA/capture-console-win32.html, https://github.com/git-for-windows/git/issues/399, https://github.com/rprichard/winpty, and https://github.com/docker/toolbox/issues/231 in hand and run with them, please feel free. – JdeBP Dec 10 '15 at 12:58

5 Answers5

63

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
  • 741
  • 5
  • 7
  • Thanks, I've been trying to figure out for a while now why this appeared to sometimes work and sometimes not, and that was the difference! – Chris Haas Feb 26 '20 at 18:50
  • 3
    the problem you're encountering is that `php` is a aliased to `winpty php` by default when running `mintty`. `php.exe` is not aliased, so it won't be launched using `winpty`. The aliases are setup by default because of compatibility issues, you may encounter those instead when not running `winpty`. – CervEd May 19 '21 at 08:41
  • Thanks! This worked for me with `node` as well, so: `$ node.exe programname.js > output.file` – Phil Ryan Sep 01 '23 at 01:47
29

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
  • 3
chtenb
  • 1,755
  • 2
  • 15
  • 17
  • 1
    Solved the issue for me when using `node` through `conemu`. – jakub.g Sep 19 '18 at 15:32
  • Thank you so much...This worked for me. – HassanSh__3571619 Oct 29 '19 at 23:03
  • 3
    This one should be accepted as the correct solution – http8086 Feb 20 '20 at 02:32
  • it's a `winpty` error, `git-bash` sets up aliases for `node ipython php php5 psql python2.7` to use `winpty` in the script `/etc/profile.d/aliases.sh` – CervEd May 19 '21 at 08:35
  • just logged in to upvote this. With default docker desktop install and git for windows, I can now run docker exec -it from a script with the docker command defined as : DOCKER_COMMAND='winpty -Xallow-non-tty -Xplain docker' Thanks a lot! Note that the options are not needed on the command line in a shell, but apparently inside a script it does. – Vincent Gerris May 21 '21 at 12:17
24

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

targnation
  • 341
  • 2
  • 4
3

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
  • 1
  • 1
  • 3
RayLuo
  • 259
  • 2
  • 6
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
  • 202
  • 1
  • 10
  • Sorry, i did comment on the wrong place. please run "strace php -i" and paste the output (last few lines at first). –  Dec 10 '15 at 10:11