Composer 安装错误 - 输出不是 tty,输入不是 tty

Composer installation error - output is not a tty, input is not a tty

我正在尝试通过 php 安装作曲家,如他们的网站所述。

php -r "readfile('https://getcomposer.org/installer');" | php

但是显示如下错误:

$ php -r "readfile('https://getcomposer.org/installer');" | php
output is not a tty
input is not a tty

我在 windows 7 并使用 git bash 来执行此命令。在 windows 命令提示符下,它工作正常。仅当我 运行 来自 git bash 2.6.2-64 位的此命令时才会出现此问题。

顺便说一句,我已经为 windows 安装了 composer,并且工作正常。但是我不能用这种方式下载composer.phar。我该如何解决这个问题?

可能是 PATH 或编码问题:

it seems that git ls-remote origin, run from a freshly-built and installed MinGW Git fails to be able to output anything, and git ls-remote origin | cat (a trick learned from working with old MSys'/MinGW's quirks) only says: output is not a tty (the exit code is 127, suggesting that some executable was not found, but it is very difficult to say which one because not even debug print statements to stderr are shown; It seems that in case of a crash or of a die(), stderr is not flushed)

  • issue 519 甚至建议取消别名 winpty

      unalias $(alias | grep winpty | cut -d"=" -f1 | cut -d" " -f2)
    

但是:

No, we cannot simply abandon winpty. PHP can be run interactively, i.e. it requires a proper Win32 Console. Running PHP without winpty in MinTTY would not provide that Console instance, leaving you with a seemingly unresponsive terminal.

See git-for-windows/build-extra@44ed99b, #399 and #400 to understand what havoc you would wreak by simply removing those aliases.

所以现在,bash 控制台与通过管道执行 php 不兼容(因为第二个 | php 可能无法从 winpty 中受益,这似乎是需要的当程序需要 Win32 控制台进行交互使用时)。

Peh points out :

If you use C:`Program Files\Git\bin\bash.exeinstead ofC:\Program Files\Git\git-bash.exe`, then the command works fine.
I'm using it in combination with ConsoleZ without any problems

这可能是因为 bash.exe 不使用 winpty,与 git-bash.exe 相反。

VonC 的回答是正确的,为了以后帮助其他人,我想提供一个更直观的解决方案。

  • 导航到 C:\Program Files\Git\bin
  • 双击bash.exe

  • 您现在应该会看到一个命令提示符。

  • 导航到您的 PHP 项目目录并安装 Composer。

    $ cd C:\path\to\your\project

    $ curl -sS https://getcomposer.org/installer | php

    $ls

  • 文件 composer.phar 现在在项目根目录中可见。

  • 使用 composer 安装包。

    $ php composer.phar 需要一些你想要安装的包

可以使用bash输出:C:\Program Files\Git\bin\bash.exe