32

Was looking at a tape + tap video and tried to get it to work.
OS: Windows 7 Git Bash Shell

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

stdout is not a tty.

main.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();
});

add.js:

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

winpty node main.js | ./node_modules/.bin/tap-spec doesn't fix the problem.

6 Answers 6

72

Just to add my case, I was facing similar issue. Neither solution of using winpty did help, thus I used different hint on using node.exe instead of node when running a script (from Git bash in my case).

not working:

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

working:

node.exe myscript.js < some-input.txt > some-output.txt
10
  • 3
    This worked for me on windows 10 using git-bash terminal. Commented Jun 29, 2020 at 4:19
  • 2
    Just appending ".exe" did the trick! Very interesting, huh? Commented Jul 25, 2020 at 11:57
  • 13
    Anybody have a clue why node.exe works but node doesn't?
    – enorl76
    Commented Aug 7, 2020 at 16:41
  • 18
    @enorl76 It took a moment to get this, but Git bash is establishing some aliases in its <INSTALLDIR>/etc/profile.d/aliases.sh. This includes node which is tested for existing prior to declaring alias node="winpty node.exe". So, node is implicitly run through winpty while node.exe is not. Commented Aug 7, 2020 at 21:40
  • 1
    The alias has been installed as part of Git Bash and so you should expect it to be restored each time you install another upgrade for that. Maybe it is possible to have another profile script in your home folder resetting that centrally declared alias. Commented Aug 10, 2020 at 18:27
6

Diagnose :

Theres nothing wrong with the code, I get the following output : (OS : ArchLinux)

  add: two numbers add correctly

    ✔ should be equal


  total:     1
  passing:   1
  duration:  14ms

Its probably a problem with Windows 7 Git Bash Shell

I read somewhere : sending output through a pipe is broken with Git Bash

To discard it run the following command :

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

For it to work you need the following output : true


Solution (for Windows):

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

Using the winpty tool, it creates a hidden console and marshals I/O between it and Cygwin/GitBashshell emulated pty :

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

READ MORE : Node.js doesn't run as tty on windows / cygwin Issue#3006

5
  • How did you run the winpty command that is different from my original post? It failed for me. What are the exact commands you are typing? Thanks Commented Aug 25, 2017 at 23:25
  • 1
    @FreddyNoNose, like I state in the answer :the winpty command would be the compiled winpty tool
    – EMX
    Commented Aug 25, 2017 at 23:34
  • 1
    @FreddyNoNose : I don't use Windows, but if you follow the answer you will get it to work with Git Bash Shell
    – EMX
    Commented Aug 25, 2017 at 23:37
  • Thanks but it appears the official position is that it is not supported. Ref: github.com/nodejs/node/issues/14100 Commented Aug 25, 2017 at 23:48
  • 5
    The solution to fix it, is to use the -Xallow-non-tty argument for winpty . Here's an example that errors as "not a tty" when used on git-bash. It's fixed by running winpty -Xallow-non-tty python --help | less
    – ninMonkey
    Commented Sep 30, 2019 at 20:06
4

Just switch from git bash to cmd first

$ cmd
3

I had same problem on console "stdout is not a tty"

This because of console, while installing Git there is an option which is choosing default terminal. Install again Git and choose terminal as Windows console and after that it should be fine.

enter image description here

1
  • 4
    Did not work for me, ended with another problem. What did work for me was using "Windows Powershell" which is embedded in Windows10. Commented Nov 10, 2019 at 0:13
2

If you use GitBash in Windows

In the file ./bash_profile you must add that :

alias docker='winpty -Xallow-non-tty -Xplain docker'
1

node generateData.js > db.json runs on Visual Studio Code's Terminal : bash

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.