WSL: Unable to pipe Bash output to other programs
I’m unable to spawn Bash from NodeJS. If you try to, it will return this error: Error: 0x80070057
How to reproduce:
- Install NodeJS
- Run
nodein CMD - Type:
cp = require('child_process');
proc = cp.spawnSync('cmd', ['/c', 'bash -c "ls"'], {encoding: 'utf8'}).output
It outputs:
[ null, 'Error: 0x80070057\r\r\n', '' ]
ref: https://github.com/Microsoft/CommandLine-Documentation/issues/8
About this issue
- Original URL
- State: closed
- Created 11 years ago
- Reactions: 6
- Comments: 41 (12 by maintainers)
Update on our oldest open issue.
The new Insider build, 14901, has some updates here. The following commands now work:
In Node on Windows:
The following does not work.
Out.txt only has the text:
Error: 0x80070057. We are aware of this one and working on it.I’ve just purposed a UserVoice Idea for this problem. Anyone who wants to see this fixed, can vote for it.
Is there any ETA when this fix will be rolled out to non-insiders?
@alanzanattadev - As @aseering mentioned you won’t have to wait long. Creators update is coming soon.
@raeesbhatti We have some changes coming to Insider builds which will allow pipe and file redirection to and from bash.exe. Stay tuned to the release notes.
I have been fighting this bug myself for a few hours and found this issue. I have managed to create a TEMPORARY workaround for devs fighting this bug. You can find the .Net project here and you can either use it as is, or adapt the code for other languages. This work-around/project/code is MIT licensed, so have at it.
Basically, it forwards any args passed to it to Bash and tells Bash to pipe its output (using /mnt/c/…) to a temp file and then after Bash exits the file is read and output. This output CAN be redirected using any of the standard methods.
PLEASE note, this is VERY quick and dirty. Feel free to submit pull requests as you see fit.
Hi @alanzanattadev – WSL changes (excluding serious security flaws and similar) are batched and merged to stable Windows 10 only as part of major Windows releases. The next major Windows release is the “Creators” update. Note that this will be the first update after WSL’s initial public release, so basically everything active or pending in this ticket-tracker is targeted at it 😃
Microsoft has not stated a release date yet for Creators, but the latest Internet rumors have it coming out in a month or so.
Has this been fixed in an insider build? Bash still cannot run as a shell in emacs (I’m on build 14965): https://github.com/syl20bnr/spacemacs/issues/6751
node.js spawn have the same problem. and
popenin C++ have the problem(tested with Dev-c++).however,If there is no output,then It works fine. here is an example: a.cpp
main.cpp
g++ a.cpp -o a then compile and run main.cpp in windows. the out.txt file appear with the right content.
so here is a temporary solution: 1.use a wraper to write everything into a file 2.read that file in windows
2016/04/15 update: It turn out system works just fine in C++(at least in Dev-C++/TDM-GCC),both
bash -c "ls >out.txt"andbash -c "ls"works fine. However, when node.js called it, above problem appeared.