stdout 不是 tty。将 bash 用于节点 + 磁带 + tap-spec

Fre*_*ose 9 node.js git-bash node.js-tape

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

node main.js | ./node_modules/.bin/tap-spec
Run Code Online (Sandbox Code Playgroud)

stdout 不是 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();
});
Run Code Online (Sandbox Code Playgroud)

添加.js:

module.exports = function(a, b) {
return a + b;
};
Run Code Online (Sandbox Code Playgroud)

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

Tho*_*ban 23

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

不工作:

node myscript.js < some-input.txt > some-output.txt
Run Code Online (Sandbox Code Playgroud)

在职的:

node.exe myscript.js < some-input.txt > some-output.txt
Run Code Online (Sandbox Code Playgroud)

  • 有人知道为什么“node.exe”可以工作但“node”不行吗? (4认同)
  • @enorl76花了一些时间才得到这个,但是 Git bash 正在其`&lt;INSTALLDIR&gt;/etc/profile.d/aliases.sh`中建立一些别名。这包括在声明 `alias node="winpty node.exe"` 之前测试是否存在的节点。因此,“node”是通过 winpty 隐式运行的,而“node.exe”则不是。 (4认同)
  • 这对我在 Windows 10 上使用 git-bash 终端有用。 (3认同)
  • 只需附加“.exe”就可以了!很有趣,是吧? (2认同)

EMX*_*EMX 5

诊断 :

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

  add: two numbers add correctly

    ? should be equal


  total:     1
  passing:   1
  duration:  14ms
Run Code Online (Sandbox Code Playgroud)

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

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

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

node -p -e "Boolean(process.stdout.isTTY)"
Run Code Online (Sandbox Code Playgroud)

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


解决方案(适用于 Windows):

$ node -p -e "Boolean(process.stdout.isTTY)"
false
Run Code Online (Sandbox Code Playgroud)

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

$ winpty node -p -e "Boolean(process.stdout.isTTY)"
true
Run Code Online (Sandbox Code Playgroud)

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

  • 修复它的解决方案是使用“winpty”的“-Xallow-non-tty”参数。下面是一个在 git-bash 上使用时错误为“not a tty”的示例。它可以通过运行`winpty -Xallow-non-tty python --help | 来修复。少` (5认同)