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

Linux Subsystem on Windows: EINVAL error when piping into Node in a cmd.exe started from bash #18638

Closed
igabesz opened this issue Feb 8, 2018 · 5 comments

Comments

@igabesz
Copy link

igabesz commented Feb 8, 2018

  • Version: v8.9.0 and v8.9.4
  • Platform: Windows 10 / Linux Subsystem on Windows
  • Subsystem: 1709 16299.125 / Ubuntu 14.04.5 LTS

I have a bash script that runs a cmd that pipes something into the Node.js executable under Windows. Like this:

$ /mnt/c/Windows/System32/cmd.exe /C "echo console.log('hi') | node"

I get the following error:

Error: EINVAL: invalid argument, uv_pipe_open
at new Socket (net.js:200:18)
at createWritableStdioStream (internal/process/stdio.js:164:16)
at process.getStdout [as stdout] (internal/process/stdio.js:14:14)
at console.js:246:38
at NativeModule.compile (bootstrap_node.js:596:7)
at Function.NativeModule.require (bootstrap_node.js:541:18)
at setupGlobalConsole (bootstrap_node.js:310:41)
at startup (bootstrap_node.js:70:7)
at bootstrap_node.js:608:3

This script worked perfectly until the recent major Windows update. And even now both of the following lines are good.

$ /mnt/c/Windows/System32/cmd.exe /C "echo console.log('hi')"
\ cmd /C "echo console.log('hi') | node"

But somehow the cmd.exe piping breaks Node if it is started from Linux. I don't know if this belongs to the Node.js team or the guys at Microsoft broke something. Anyway, looking forward to see some analysis.

PS. My Stack Overflow question is here:
https://stackoverflow.com/questions/48670794/linux-subsystem-on-windows-node-js-einval-error

@igabesz
Copy link
Author

igabesz commented Feb 8, 2018

Update: this also breaks meaning that it's not about the pipe but rather the startup of Node itself.

/mnt/c/Windows/System32/cmd.exe /C "node"

@mihab
Copy link

mihab commented Feb 11, 2018

Yup got the same error with latest LTS of Node, anyone knows of a workaround?

@thasmo
Copy link

thasmo commented Feb 17, 2018

With node 9.5.0 for me EINVAL errors happen when resizing the terminal window, as described in #9542.

@bzoz
Copy link
Contributor

bzoz commented Feb 19, 2018

This is an issue with the WSL, not Node - GetFileType for stdio handles returns FILE_TYPE_PIPE, then when libuv tries to call SetNamedPipeHandleState it fails with ERROR_INVALID_FUNCTION.

Try running Linux version of Node. You can also try redirecting Node output to a real pipe (e.g. by adding | cat) or a file.

@bzoz bzoz closed this as completed Feb 19, 2018
@wony-zheng
Copy link

when i run libuv in windows:

uv_pipe_t stdin_;
uv_pipe_init(uv_default_loop(), &stdin_, 0);
uv_pipe_open(&stdin_, 0);   // return EINVAL in windows,

after dig into the source , i found the lasterror from SetNamedPipeHandleState() is ERROR_INVALID_FUNCTION. how to fix this error ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants