Skip to content
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

process.stdin never returns with using Git Bash for Windows #5620

Closed
mysticatea opened this issue Mar 9, 2016 · 21 comments
Closed

process.stdin never returns with using Git Bash for Windows #5620

mysticatea opened this issue Mar 9, 2016 · 21 comments
Labels
child_process Issues and PRs related to the child_process subsystem. process Issues and PRs related to the process subsystem. windows Issues and PRs related to the Windows platform.

Comments

@mysticatea
Copy link

  • Version: v4.4.0 and v5.7.1
  • Platform: Windows 64bit

From mysticatea/npm-run-all#24

process.stdin getter stops a program in the following case:

  • On Git Bash of Git for Windows (MINGW64)
  • Executing cmd.exe (e.g. child_process.exec)
  • Inheriting stdin.

This is a repro steps:

$ cmd /C="node test.js"
"use strict";

const name = process.argv[2] || "parent";

console.log("before stdin:", name, process.binding('tty_wrap').guessHandleType(0));
process.stdin;
console.log("after stdin:", name);

if (process.argv[2] !== "child") {
    require("child_process").spawn(
        process.argv[0],
        [process.argv[1], "child"],
        {stdio: "inherit"}
    );
}

The results of above:

cmd.exe OK

C:\Users\t-nagashima.AD\Documents\GitHub\WebDevolopment\Pizzeria-ES2015>cmd /C=node test.js
before stdin: parent TTY
after stdin: parent
before stdin: child TTY
after stdin: child

PowerShell OK

PS C:\Users\t-nagashima.AD\Documents\GitHub\WebDevolopment\Pizzeria-ES2015> cmd /C="node test.js"
before stdin: parent TTY
after stdin: parent
before stdin: child TTY
after stdin: child

Git Shell of GitHub for Windows OK

C:\Users\t-nagashima.AD\Documents\GitHub\WebDevolopment\Pizzeria-ES2015 [master +1 ~1 -0 !]> cmd /C="node test.js"
before stdin: parent TTY
after stdin: parent
before stdin: child TTY
after stdin: child

Git Bash of Git for Windows Wrong

t-nagashima@T-NAGASHIMA4 MINGW64 /c/Users/t-nagashima.AD/Documents/GitHub/WebDevolopment/Pizzeria-ES2015 (master)
$ cmd /C="node test.js"
before stdin: parent PIPE
after stdin: parent
before stdin: child PIPE

The program stops at process.stdin, then "after stdin: child" has never printed.
If I types Enter Key, the program resumes.

@mscdex mscdex added windows Issues and PRs related to the Windows platform. process Issues and PRs related to the process subsystem. child_process Issues and PRs related to the child_process subsystem. labels Mar 9, 2016
@evanlucas
Copy link
Contributor

/cc @nodejs/platform-windows

@rvagg
Copy link
Member

rvagg commented Mar 9, 2016

smells like it might be related to #5384

@mysticatea
Copy link
Author

#5384 (comment) seems to be fixed on v6.2.0.
But this is still an issue.

@seishun
Copy link
Contributor

seishun commented Oct 13, 2016

Simpler testcase: node.exe test.js in Git Bash.

This happens because the call to pNtQueryInformationFile hangs here.

Might be a Windows bug?

Pinging @orangemocha @piscisaureus @saghul

@saghul
Copy link
Member

saghul commented Oct 13, 2016

@seishun I'm not sure what happens in that case TBH. Git Bash is a MSYS based environment AFAIK, so I wonder if it will load that super-old CRT MSYS was based on.

@seishun
Copy link
Contributor

seishun commented Oct 13, 2016

@saghul Do you mean C runtime library? That's irrelevant since NtQueryInformationFile is a Win32 function, right?

Also Git Bash is based on MSYS2 nowadays, which is a recent fork of Cygwin.

@saghul
Copy link
Member

saghul commented Oct 13, 2016

Yes, it's a Win32 API function, but stdin / out / err are CRT fds, so I guess the problem comes somewhere around there.

@joaocgreis
Copy link
Member

This is related to #3006 .

In Git Bash, with node.exe test.js I get the issue described here (PIPE), but with node test.js it works fine (TTY). However, winpty works well either way:

winpty node.exe test.js
winpty node test.js

@seishun
Copy link
Contributor

seishun commented Oct 15, 2016

In Git Bash, with node.exe test.js I get the issue described here (PIPE), but with node test.js it works fine (TTY).

In case anyone is wondering, this is because Git Bash aliases node to winpty node.exe. According to @dscho, they have to read fewer bug reports this way (see git-for-windows/git#738 (comment)).

@bnoordhuis
Copy link
Member

Hah, and instead we get to deal with the fallout? Nice!

Am I right in concluding that this is an environmental issue not directly caused by or under control of node? If yes, I move to close.

@dscho
Copy link

dscho commented Oct 17, 2016

Hah, and instead we get to deal with the fallout? Nice!

Sorry for that.

Am I right in concluding that this is an environmental issue not directly caused by or under control of node?

Yes, the problem is caused by MinTTY using the tty emulation of MSYS2's runtime (which is a portable version of the Cygwin runtime), and node expecting to talk to a real Win32 Console (which the winpty bridge provides and synchronizes to the MSYS2 tty).

If yes, I move to close.

FWIW I agree.

@bnoordhuis
Copy link
Member

Thanks for chiming in. Okay, I'll go ahead and close.

@yairEO
Copy link

yairEO commented Nov 1, 2016

Hey guys, I'm not as technical as you, but I followed all the links here and in other issues and have read it all (didn't understand much, since my programming skill-set is only client-side), and I didn't fully get what is the status of the git bash colors issue?

should I download any new version of anything? because I'm already on latest GIT (windows port) so should I try Node7? I'm not sure what to do to see colors on my Git Bash :(

@gibfahn
Copy link
Member

gibfahn commented Nov 1, 2016

@yairEO I don't think this issue was related to colours on Git bash. What exactly is the issue you're seeing?

This issue is a problem with Git Bash not with node, the workaround is to run node your_file.js instead of node.exe your_file.js.

@yairEO
Copy link

yairEO commented Nov 1, 2016

@gibfahn - thank you, I followed the maze of issues pointing to one another until I ended up here, at the bottom of the trail, so I thought it wouldn't hurt asking, but luckily I was helped in another thread

@benjamingr
Copy link
Member

@yairEO in the future you're very welcome to ask questions at https://github.com/nodejs/help

@ltvan
Copy link

ltvan commented Nov 25, 2016

I think that this should help:
alias -p npm="winpty npm.exe"

Run it in git-bash once and you can use 'npm test'

@ltvan
Copy link

ltvan commented Nov 25, 2016

Actually you should run this instead and restart git-bash:
echo alias -p npm=\"winpty npm.exe\" >> ~/.bashrc

@dscho
Copy link

dscho commented Nov 25, 2016

@ltvan does this really fix the problem with the script described in this ticket?

If so, would it not make more sense to add npm handling to https://github.com/git-for-windows/build-extra/blob/db6871f1f5490670456f2869387c7e9fcb6b5d9c/git-extra/aliases.sh#L13 ?

@ltvan
Copy link

ltvan commented Nov 25, 2016

It does work in my environment. Adding to git-extra is good so.

However, if you run through gulp or grunt, the winpty gulp won't work.

@soletan
Copy link

soletan commented Mar 30, 2020

In opposition to workaround given by @gibfahn above I had to use node.exe instead of node to get some script processing content redirected on stdin, so my workaround is the opposite to his suggestion.

didn't work:

node ./processor.js < input > result

did work:

node.exe ./processor.js < input > result

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
child_process Issues and PRs related to the child_process subsystem. process Issues and PRs related to the process subsystem. windows Issues and PRs related to the Windows platform.
Projects
None yet
Development

No branches or pull requests