stdout is not a tty. Using bash for node + tape + tap-spec
Asked Answered
K

6

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.

Krissykrista answered 25/8, 2017 at 22:55 Comment(0)
H
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

Headless answered 25/8, 2017 at 23:17 Comment(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? ThanksKrissykrista
@FreddyNoNose, like I state in the answer :the winpty command would be the compiled winpty toolHeadless
@Krissykrista : I don't use Windows, but if you follow the answer you will get it to work with Git Bash ShellHeadless
Thanks but it appears the official position is that it is not supported. Ref: github.com/nodejs/node/issues/14100Krissykrista
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 | lessSchoolboy
F
70

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
Framing answered 23/6, 2020 at 10:22 Comment(10)
This worked for me on windows 10 using git-bash terminal.Lashundalasker
Just appending ".exe" did the trick! Very interesting, huh?Wormhole
Anybody have a clue why node.exe works but node doesn't?Fetiparous
@Fetiparous 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.Framing
@ThomasUrban seems like it makes sense to undo the node alias then? Sorry I'm a noob Windows user and new to git bash, although I definitely see how much I've been missing with cmd as opposed to bashFetiparous
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.Framing
Thanks. This fixed the issue for me with python in MSYS2 on Windows 10. Didn't work: python foo.py >bar. Did work: python2.7.exe foo.py >bar (yes, we're stuck in python 2.7 still, but finally transitioning to 3). For my own curiosity, and for anyone curious: I tried which python and got /c/msys64/mingw64/bin/python. I then tried which python2.7.exe and got /c/msys64/mingw64/bin/python2.7.exe.Handed
@GaryFixler There is nothing curious about this for bash is a tool usually found in Linux operating system which doesn't care for filename extensions. In Linux, python and python.exe are different entries in filesystem and there is no implicit idea of looking up python.exe if python doesn't match any file. That's specific to Windows. So, in your case there might be two distinct files matching either name or one of them is a symbolic link to the other.Framing
@ThomasUrban - yes (I've been all-Linux at home since 2006), but MSYS2 on Windows (which I have to use at work) works a bit differently. You can call Windows executables without the .exe. There's a python.exe in that folder, but no python, but I can still ls -i python, which lists the files as python, and gives the same inode as ls -i python.exe. I haven't dug in deeper to see why I had to include the .exe in this case, though.Handed
you can remove the alias, node continues to work fine if you use the experimental windows console support thingLyrebird
H
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

Headless answered 25/8, 2017 at 23:17 Comment(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? ThanksKrissykrista
@FreddyNoNose, like I state in the answer :the winpty command would be the compiled winpty toolHeadless
@Krissykrista : I don't use Windows, but if you follow the answer you will get it to work with Git Bash ShellHeadless
Thanks but it appears the official position is that it is not supported. Ref: github.com/nodejs/node/issues/14100Krissykrista
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 | lessSchoolboy
S
4

Just switch from git bash to cmd first

$ cmd
Sparid answered 24/12, 2022 at 17:3 Comment(0)
A
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

Amplification answered 10/9, 2018 at 20:2 Comment(1)
Did not work for me, ended with another problem. What did work for me was using "Windows Powershell" which is embedded in Windows10.Menchaca
J
2

If you use GitBash in Windows

In the file ./bash_profile you must add that :

alias docker='winpty -Xallow-non-tty -Xplain docker'
Jervis answered 9/11, 2021 at 17:50 Comment(0)
C
1

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

Capper answered 6/4, 2020 at 0:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.