joyent/node — Issue #1844: --use-legacy and process redirection are broken on Windows
Author: Corion
Created: 2011-10-08 14:08:02+00:00
State: open

In nodejs 0.5.8 (Windows 32-bit build), the following immediately crashes:

`
> nodejs-versions\nodejs-0.5.8\node.exe --use-legacy -e console.log('OK')

node.js:238
stdout._handle.unref();
^
TypeError: Cannot call method 'unref' of undefined
at EventEmitter.stdout (node.js:238:26)
at Object. (console.js:26:10)
at Object. (eval at (eval:1:75))
at Object. (eval:1:63)
at Module._compile (module.js:432:26)
at startup (node.js:96:14)
at node.js:559:3
`

In version 0.5.7, the command worked as expected:
`
> nodejs-versions\nodejs-0.5.7\node.exe --use-legacy -e console.log('OK')
OK
`

It seems as if STDIO is broken on Windows. This is problematic as it seems that nodejs also uses this "legacy" mode when it is launched from within another program with its standard IO redirected to other file handles. This works with 0.5.7:

`
C:\Projekte\NodeJs-RemoteObject>nodejs-versions\nodejs-0.5.7\node.exe -e console.log('OK') |perl -ple "s!$! piped to $^X!"
OK piped to C:\strawberry\perl\bin\perl.exe
`

... but fails fatally with 0.5.8, without any recourse to launch nodejs as subprocess and receive data from it:

`
C:\Projekte\NodeJs-RemoteObject>nodejs-versions\nodejs-0.5.8\node.exe -e console.log('OK') |perl -ple "s!$! piped to $^X!"

node.js:207
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: write EINVAL
at errnoException (net_uv.js:566:11)
at Socket.write (net_uv.js:389:18)
at Object. (console.js:26:18)
at Object. (eval at (eval:1:75))
at Object. (eval:1:63)
at Module._compile (module.js:432:26)
at startup (node.js:96:14)
at node.js:559:3

`