-
Notifications
You must be signed in to change notification settings - Fork 30.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Node.js doesn't run as tty on windows / cygwin #3006
Comments
IIRC, that's because the cygwin shell isn't really a tty, it's a pipe. |
I am confused (general state of mind these days): Ain't I supposed to be able to do things like |
|
Let me rephrase the question: In my understanding Note: clarification on Cygwin: I meant the Cygwin bash. |
You can |
I am sorry to ask differently yet again: Does this mean that there is no reliable way to figure out whether node (or any other app) is running inside a terminal? (I am asking because http://stackoverflow.com/questions/4426280/what-do-pty-and-tty-mean tells me that |
If by 'terminal' you mean 'user-visible window', then no, not in general and not reliably. |
I need to ask again to form a good question here (so sorry for taking your time - and anyone who reads this). I am still not clear what |
Short version: Cygwin sucks. Don't use it. 😄 Medium version: Cygwin (and others) that attempt to provide "terminal windows" have a lot of problems with standard Windows programs (e.g. node). Long version... POSIX has pty's, which allows programs to work the same way on the console, serial terminals, ssh sessions, and GUI terminal windows (e.g. XTerm). The program sees a standard "tty" interface in all cases, and can easily differentiate this interface from a pipe or file redirection. Windows has no equivalent feature. Windows consoles are a special facility built in to the OS, and generally aren't extensible. The Windows console can do things that no other application can do. cygwin (and others) attempt to emulate POSIX pty's and provide "terminal windows" with varying degrees of success. These terminal windows are generally NOT Windows consoles, and can confuse standard Windows programs (e.g. node). Some of them use pipes, but pipes have problems. A program with a pipe for stdin or stdout has no way to know if it's being run in a traditional shell pipeline (e.g. "ls -l | head"), or if the other end of the pipe is a process attempting to emulate an interactive tty. |
@mcnameej Thank you for your detailed explanation. The problem with this situation is that the bash of cygwin and the bash of github have been promoted widely in the nodeschool community. I also meet many windows developers that use it in their corporate computers. I seem to have the following problems after processing all your great input:
|
bash itself is not the problem -- the problem is running node inside a "fake" console. If you run bash in a regular Windows console, it gets along fine with node. See screen shots below. .
I don't know what changed. A review of the code (probably in libuv) could probably determine the cause, but IMHO, that's asking the wrong question. You're trying to do something that is inherently unreliable on Windows, and any "fix" made today may break again tomorrow.
I'm not the right person to answer that; perhaps @bnoordhuis will chime in. I have a lot of experience with Win32, and can talk about the OS-level issues, but I'm not an expert on node's internals. |
@mcnameej Don't have time for a lengthy reply but there is one thing to point out: those screenshots are made with win 7, the problem has been reported with windows 8.1 |
(My lengthy reply)
It should but somehow it seems it doesn't as hinted by the screenshots of @LuigiR0jas above. Do you have an idea why his bash returns something different than yours? Is there a way to find out the difference between these two setups?
It is not about trying to "fix" it windows for me. It is however important to me to write command line tools that work predictably and reliably on windows. I haven't had the chance to test it but it seems like the cli of other tools seems to work fine?! If the bash is up and running what is the practical difference between isTTY being true and false? (why does node need to adapt to it?) |
@LuigiR0jas: Please try this... Use Windows Explorer to navigate to wherever you have Cygwin installed. There should be a Cygwin.bat file in the base directory. Double click on that file to run it from Explorer. This will open Cygwin bash inside a standard Windows console. Change to the node directory (e.g. Run It should print true. I just did a fresh install of Cygwin on Windows 8.1 X64 and verified these results. The "Cygwin Terminal" shortcut runs bash inside Cygwin's fake console. The fake console doesn't get along with node. |
See my message above to LuigiR0jas. I suspect he was using Cygwin's fake console. The problem isn't bash -- it's the console.
Unfortunately, the Cygwin people have different priorities. They want their environment to be as "POSIX-ish" as possible, even if that causes problems with some native Windows programs.
Tools that work with pure ASCII input and output streams generally work fine inside fake consoles. They don't care if their stdin/stdout are pipes. Tools that do special input processing (e.g. read single characters rather than lines), or that colorize their output, will fail.
The problem is that Window has console-specific API's, which node uses when run inside a real Windows console. Node falls back to generic I/O functions when stdin/stdout are anything other than a real console (e.g. pipe, redirected to file, etc.). Having console-specific I/O functions is a key difference between Windows and POSIX. |
Short question: in the bash without |
Proves what I'm saying. The problem isn't bash -- it's the console. |
I'm not sure what that test will prove. cygwin's own programs (bash, vim, emacs, etc.) know how to deal with both real Windows consoles and cygwin's terminal. They'll work either way. The problem is with standard Windows console applications (e.g. node) running inside cygwin's terminal. |
@mcanameej I never doubted your word. Just need to go 100% clear in understanding to phrase it correctly when passing on. There is still some question open:
Just for the sake of argument: could you compile nodejs with cygwin and it would work?
So it is possible to read lines and output text in those terminals?! |
I went over and looked at workshopper/workshopper#120 and nodeschool/discussions#1448 that were mentioned by @SomeoneWeird. I strongly suspect there is a bug in node v4 (probably in libuv) related to setting Windows 8/8.1/10 consoles into raw mode. I can reproduce the failure in a standard console. This is a completely separate issue from running node inside cygwin's fake console. |
AFAIK, node doesn't support building under cygwin. Somebody might be able to hack it, but I'm afraid it won't be me.
I don't understand the question.
Yes. When running node in a fake console, it's useful to imagine that you're running it with input and output redirected to files (e.g.
Windows consoles don't implement ANY escape sequences. node (via libuv) emulates them when it detects itself running in a console. Behind the scenes, libuv parses the escape sequences and makes the appropriate Windows console API calls to implement them. |
or 7 ? |
No. I tried to fix it, but gave up, see #2908 (comment) I just rebased my branch at https://github.com/sam-github/node/tree/spawn-detached-window-hide-option, feel free to adopt it if you want. I completely failed to make the pop-up windows happen at all, so could not verify that my change was capable of hiding the pop-up... if you can build and verify that branch, I could re-PR it and I'm sure we could get it merged in short order. |
I had this problem and I tried running a 'sub-shell' (mean I ran bash and the command line and created another shell). Then I ran node program < infile and I don't have the problem anymore |
It is not a node problem, I investigated this in context of yarnpkg. The way git-bash "fixed" the problem is by wrapping the node process in a program called winpty, which emulates some/enough of the unix teletype to make it work: https://github.com/rprichard/winpty If you have a "newer" version of git bash installed, you will find a hack in WinPTY works with cygwin as well, so if you introduce a similar "hack/fix" your bash profile for, it should work "just as well" in cygwin. Checkout this pull-request for further details: yarnpkg/yarn#2230 |
@thetrompf I am sorry but that seems like it is a Node.js problem after all: If you have to wrap it with some other method that "does the compatibility" it means - by what I understand - that the Node.js compatibility is not given. |
@martinheidegger Node.js works fine with the standard windows shells (cmd.exe and power shell), using cygwin/msys shells is the users who has decided to use shells that looks like teletype terminals but are not, and the common way to test if you are command line programs is running in an interactive shell is by checking for |
@thetrompf I do know that cygwin does not implement certain parts correctly. But: if cygwin would break interactive mode then it wouldn't be possible for |
note : if it can help someone there is a workaround for this issue using msys2 I guess it would be the same for cygwin the issue I face is how to write npm's output to a file using msys2. I am using msys2w64 under windows 10 the workarround is: my case is to run npm and gulp only $npm > /tmp/test
stdout is not a tty
$ this works $npm.cmd > tmp/test
$ |
@pmalhaire I use msys2 (from msys2-x86_64-20160205.exe) and do not seem to need the workaround, calling the npm shell script directly works fine. |
@geonanorch did you try to redirect it's output to a file as done in my example ? $npm > /tmp/test |
@pmalhaire yes I did:
(remark: I installed node/npm independently of MSYS2) Note that things aren't perfect for me either though: when invoking I wish there existed a 'standard' library which allowed to build windows console programs with dual support native-console/mintty... |
@geonanorch it's a workaround |
Just had a report @ nodeschool that
node -p -e "Boolean(process.stdout.isTTY)"
on Windows 8.1 Pro with Node.js 4.1.0 on Cygwin 2.2.1 returnsfalse
. It does seem to work in the regular command prompt.The text was updated successfully, but these errors were encountered: