Nodejs process.stdin.resume() doesn't work in Cygwin

Trying to make a CLI type program - waiting for user input. In Cygwin, the script just exits. Just this in the script process.stdin.resume()

Seems to work on a Linux VM. Works on Windows Command line also.

Im assuming 'terminal' stuff regarding Cygwin..

The symptom is that Cygwin process.stdin.on('data', cb); and process.stdin.on('end', cb); doesn't get called.

I found a workaround for it

Versions

> ver
Microsoft Windows [Version 6.1.7601]

$ uname -a
CYGWIN_NT-6.1 localhost 1.7.28(0.271/5/3) 2014-02-04 16:01 x86_64 Cygwin

$ node --version
v0.8.14

Maybe it works with newer node, I don't know, I need to use this version.

c:\test\myecho.js

console.error("Starting up");
process.stdin.resume();
process.stdin.setEncoding('utf8');
console.error("Waiting for data");

var inputContents = ""; 
process.stdin.on('data', function (chunk) {
    process.stderr.write(".");
    inputContents += chunk.toString();
});

process.stdin.on('end', function () {
    console.error("\nGot the full thing :)");
    console.log(inputContents);
});

let's try it on Windows

c:\test>echo hello | node myecho
Starting up
Waiting for data
.
Got
hello
c:\test>_

Let's try it in Cygwin

/cygdrive/c/test$ echo hello | node myecho
Starting up
Waiting for data
/cygdrive/c/test$ _

Let's try it again "in Cygwin"

/cygdrive/c/test$ cmd /c 'echo hello | node myecho'
Starting up
Waiting for data
.
Got the full thing :)
hello
/cygdrive/c/test$ _

Ok, now make it fancy!

/cygdrive/c/test$ cmd /c 'echo hello | node myecho 2>NUL'
hello
/cygdrive/c/test$ cmd /c 'echo hello | node myecho' 2>/dev/null
hello
/cygdrive/c/test$ _

Too bad, the input can't come from a Cygwin file descriptor, but as a workaround it's possible to write it to a file and then read it from there with type for example.

Portability

If someone wants to write a portable script calling a node app expecting standard input:

#!/bin/bash
SCRIPT_DIR='../path/to/scripts' # absolute paths would need a little more playing
if [[ `uname -s` == CYGWIN* ]]; then
  cmd /c "type file1 | node ${SCRIPT_DIR//\//\\}\program.js ${BASHVAR}" | grep stuff >file2
else
           cat file1 | node ${SCRIPT_DIR}/program.js        ${BASHVAR}  | grep stuff >file2
fi