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

Unable to pipe Bash output to other programs #2

Closed
RaeesBhatti opened this issue Apr 7, 2016 · 41 comments
Closed

Unable to pipe Bash output to other programs #2

RaeesBhatti opened this issue Apr 7, 2016 · 41 comments
Labels

Comments

@RaeesBhatti
Copy link

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 node in 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: MicrosoftDocs/WSL#8

This was referenced Apr 7, 2016
@patryk9200
Copy link

Try by changing encoding. I don't have problem to run bash -c "ls" from CMD.
Try UTF16 or Latin II (852). I have in CMD Latin II encodig by default.

@RaeesBhatti
Copy link
Author

NodesJS says unknown encoding for both UTF-16 and ISO-8859-2. And it works just find in the CMD. Just not in NodeJS

@RaeesBhatti
Copy link
Author

RaeesBhatti commented Apr 7, 2016

This is a problem with Bash having problems with output piping. If I specify { stdio: 'inhert' }, it works but that way I then have no way of getting that data. { stdio: 'pipe' } produces the error above

@RaeesBhatti RaeesBhatti changed the title Unable to spawn Bash from other programs Unable to pipe Bash output to other programs Apr 7, 2016
@RaeesBhatti
Copy link
Author

Ref: MicrosoftDocs/WSL#8 (comment)

@RaeesBhatti
Copy link
Author

/cc @russalex

@tkelman
Copy link

tkelman commented Apr 11, 2016

Same from mintty (the terminal emulator used by cygwin and msys2), which uses named pipes for stdin/stdout:

$ /cygdrive/c/windows/system32/bash
Error: 0x80070057

@russalex
Copy link
Contributor

Sorry for the late comment on this one. Main reason for the delay is that I did not want to comment until I have tried it myself and I did not have node.exe on my system.

I still get an error here on the latest build, but it at least is a different error (no more helpful).

We will look into this one, but I can not promise anything.

@RaeesBhatti
Copy link
Author

This is actually very crucial to many applications of WSL. For example in my case I have to make Atom-Hack (HackLang plugin for Atom Editor) work by executing a Hack Linter inside the WSL and pipe its output to Atom's linter. There are a lot of use cases for this.

You can actually try this on Python too as suggested here

@russalex
Copy link
Contributor

We have a known limitation where we only support the console for stdin and stdout. If either of those are not a console then we will fail. That said, I believe I'm telling you things you already know with your last comment in #20.

We do understand that this is a limitation and does block some scenarios. It is on the backlog. My suggestion at this point would be to add it to our User Voice page and go for the up votes to help raise the priority.

@wywzxxz
Copy link

wywzxxz commented Apr 14, 2016

node.js spawn have the same problem.
and popen in C++ have the problem(tested with Dev-c++).

however,If there is no output,then It works fine.
here is an example:
a.cpp

#include"stdio.h"
int main()
{
    FILE *fp=fopen("out.txt","w");
    fprintf(fp,"asdadasd\n");
    fclose(fp); 
}

main.cpp

#include"stdio.h"
#include"windows.h"
int main(int argc,char** argv)
{
    //if (argc<=1) return 0;
    system("bash -c \"./a\"");
    return 0;
}

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" and bash -c "ls" works fine. However, when node.js called it, above problem appeared.

@RaeesBhatti
Copy link
Author

RaeesBhatti commented Apr 14, 2016

I've just purposed a UserVoice Idea for this problem. Anyone who wants to see this fixed, can vote for it.

@benhillis
Copy link
Member

Thanks for creating the UserVoice page. I wanted to be clear that this is definitely very high on our internal list of things we want to implement for future updates.

@mjoppich
Copy link

Is there any quick fix around the corner ... i'd desperately love to grab the output from bash -c :S

As a first "quick fix" is it somehow possible to save the output from bash to file?

@aseering
Copy link
Contributor

I haven't tried this, but if you want to write the output to a file, could you just do that within bash? bash -c 'ls > /mnt/c/Users/me/tmp.txt'

@wywzxxz
Copy link

wywzxxz commented Apr 27, 2016

"ls > file" doesn't work for node-webkit,and as I remember,doesn't work for node.js either.
But as I mentioned above,system("bash -c 'ls > file' ") in C++ works.

@Macmee Macmee mentioned this issue Aug 22, 2022
2 tasks
@onetrev onetrev mentioned this issue Oct 14, 2022
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests