Search code examples
node.jsstdoutstdingit-bashmingw-w64

Bash + Node.js + stdin/stdout redirection: error "not a tty"


This problem may be Windows-specific. I have not tested it on Linux or Mac.

I use:

  • Windows 7 64 Bit
  • Node.js 8.1.3
  • Git for Windows 2.8.1, including GNU bash, version 4.3.42(5)-release

node my-cli.js > foo.txt: Error output is not a tty

node my-cli.js < foo.txt: Error input is not a tty.


Solution

  • Create a file my-cli:

    #!/bin/sh
    
    node "path/to/my-cli.js" "$@"
    exit $?
    

    Call ./my-cli > foo.txt or ./my-cli < foo.txt.

    This also works with arguments: ./my-cli --answer 42 > foo.txt