Skip to content

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

Closed

Description

@mysticatea
  • 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.

Activity

  1. added
    windowsIssues and PRs related to the Windows platform.
    processIssues and PRs related to the process subsystem.
    child_processIssues and PRs related to the child_process subsystem.
    on Mar 9, 2016
  2. evanlucas commented on Mar 9, 2016

    @evanlucas
    Contributor

    /cc @nodejs/platform-windows

  3. rvagg commented on Mar 9, 2016

    @rvagg
    Member

    smells like it might be related to #5384

  4. mysticatea commented on May 19, 2016

    @mysticatea
    Author

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

  5. seishun commented on Oct 13, 2016

    @seishun
    Contributor

    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

  6. saghul commented on Oct 13, 2016

    @saghul
    Member

    @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.

  7. seishun commented on Oct 13, 2016

    @seishun
    Contributor

    @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.

  8. saghul commented on Oct 13, 2016

    @saghul
    Member

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

  9. joaocgreis commented on Oct 15, 2016

    @joaocgreis
    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
  10. seishun commented on Oct 15, 2016

    @seishun
    Contributor

    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)).

  11. bnoordhuis commented on Oct 17, 2016

    @bnoordhuis
    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.

  12. dscho commented on Oct 17, 2016

    @dscho

    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.

  13. bnoordhuis commented on Oct 18, 2016

    @bnoordhuis
    Member

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

  14. yairEO commented on Nov 1, 2016

    @yairEO

    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 :(

  15. gibfahn commented on Nov 1, 2016

    @gibfahn
    Member

    @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.

  16. yairEO commented on Nov 1, 2016

    @yairEO

    @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

  17. benjamingr commented on Nov 2, 2016

    @benjamingr
    Member

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

  18. ltvan commented on Nov 25, 2016

    @ltvan

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

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

  19. ltvan commented on Nov 25, 2016

    @ltvan

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

  20. dscho commented on Nov 25, 2016

    @dscho

    @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 ?

  21. ltvan commented on Nov 25, 2016

    @ltvan

    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.

  22. soletan commented on Mar 30, 2020

    @soletan

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    child_processIssues and PRs related to the child_process subsystem.processIssues and PRs related to the process subsystem.windowsIssues and PRs related to the Windows platform.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions