13

正在看磁带+点击视频并试图让它工作。
操作系统:Windows 7 Git Bash Shell

node main.js | ./node_modules/.bin/tap-spec

标准输出不是 tty。

主.js:

var test = require('tape');
var add = require('./add');

test('add: two numbers add correctly', function(t) {
var actual = add(1,2);
var expected = 3;
t.equal(actual, expected);
t.end();
});

添加.js:

module.exports = function(a, b) {
return a + b;
};

winpty 节点 main.js | ./node_modules/.bin/tap-spec 不能解决问题。

4

5 回答 5

34

只是为了补充我的情况,我面临着类似的问题。使用 winpty 的解决方案都没有帮助,因此我在使用时使用了不同的提示,node.exe而不是node在运行脚本时(在我的例子中来自 Git bash)。

不工作:

node myscript.js < some-input.txt > some-output.txt

在职的:

node.exe myscript.js < some-input.txt > some-output.txt
于 2020-06-23T10:22:23.300 回答
5

诊断 :

代码没有问题,我得到以下输出:(操作系统:ArchLinux)

  add: two numbers add correctly

    ✔ should be equal


  total:     1
  passing:   1
  duration:  14ms

它可能是一个问题Windows 7 Git Bash Shell

我在某处读到:Git Bash 破坏了通过管道发送输出

要丢弃它,请运行以下命令:

node -p -e "Boolean(process.stdout.isTTY)"

要使其工作,您需要以下输出:true


解决方案(适用于 Windows):

$ node -p -e "Boolean(process.stdout.isTTY)"
false

使用winpty 工具,它创建一个隐藏控制台并在它和 Cygwin/GitBashshell 模拟 pty 之间编组 I/O:

$ winpty node -p -e "Boolean(process.stdout.isTTY)"
true

阅读更多:Node.js 在 windows / cygwin 问题#3006 上不作为 tty 运行

于 2017-08-25T23:17:17.803 回答
1

node generateData.js > db.json 在 Visual Studio Code 的终端上运行:bash

于 2020-04-06T00:19:49.980 回答
1

我在控制台上遇到了同样的问题“stdout 不是 tty”

这是因为控制台,在安装 Git 时有一个选择默认终端的选项。再次安装 Git 并选择终端作为 Windows 控制台,然后就可以了。

在此处输入图像描述

于 2018-09-10T20:02:17.280 回答
0

如果你在 Windows 中使用 GitBash

在文件 ./bash_profile 中,您必须添加:

alias docker='winpty -Xallow-non-tty -Xplain docker'
于 2021-11-09T17:50:17.123 回答