【问题标题】:Why does git still print to the screen when both stdout and stderr have been redirected?为什么当 stdout 和 stderr 都被重定向时,git 仍然打印到屏幕上?
【发布时间】:2019-06-08 08:10:03
【问题描述】:

我想静音在我的 CI 系统中使用的 git push 命令的输出,这可能会泄漏敏感信息。

命令是:

git --quiet push > /dev/null 2>&1

所以它不应该在屏幕上打印任何东西。但是当身份验证失败时,它仍然会打印Password for 'https://xxxx@github.com':

怎么会发生这种情况以及如何将其静音?

更新: 虽然我不确定,但我猜 git 会调用getpass() 或类似的东西直接写给/dev/tty

【问题讨论】:

  • 用这个测试重现这里@9​​87654325@

标签: git shell command-line


【解决方案1】:

为了防止密钥记录和解决重定向密码提示是通过/dev/tty 完成的。在 Python 的getpass 中查看这是如何完成的。

【讨论】:

    【解决方案2】:

    Git 显式打开/dev/tty 用于读取写入,用于密码提示。

    /dev/tty 在 1979 年左右被添加到 Unix,允许程序获取控制终端的文件描述符,因此当 stdin 被占用以及 stdout 和 stderr 都被重定向时,用户输入成为可能。

    How does less take data from stdin while still be able to read commands from user?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-24
      • 1970-01-01
      • 2011-08-10
      • 2019-06-14
      • 2014-07-22
      • 1970-01-01
      相关资源
      最近更新 更多