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 #8

Closed
RaeesBhatti opened this issue Apr 6, 2016 · 5 comments
Closed

Unable to pipe Bash output to other programs #8

RaeesBhatti opened this issue Apr 6, 2016 · 5 comments

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', '' ]
@justinhixson
Copy link

This is actually a pretty interesting one. in Python, for example, I can spawn bash just fine with the subprocess module, but only under certain circumstances. consider the following script:

import subprocess
subprocess.run(["bash","-c","ls"])

this is saved as bash.py

c:\>python bash.py works

c:\>python
>>import subprocess;
>>subprocess.run(["bash","-c","ls"])

also works

however, I found it very interesting that

C:\>echo import subprocess; subprocess.run(["bash","-c","ls"]); | python 

does NOT work. same Error: 0x80070057

(note that something like

C:\>echo import subprocess; subprocess.run(["notepad"]); | python

does indeed work.)

I was using python 3.5 for these tests.

I am sure that it is much more complicated than this, but bash.exe seems to be really, really offended by stream redirection with pipes. that doesn't clearly explain why OP is having a problem with node.js, but note that this is exactly the same error that you would get if you ever try to pipe something into bash.exe at all. for instance:

C:\Users\Justin>type rocks.sh
#!/bin/bash
echo "bash on Windows ????!" | sed 's/????/rocks/g'

C:\Users\Justin>bash rocks.sh
bash on Windows rocks!

C:\Users\Justin>type rocks.sh | bash
Error: 0x80070057

C:\Users\Justin>type rocks.sh | bash -c "sh"
Error: 0x80070057

C:\Users\Justin>bash -c "sh"
# rocks.sh
bash on Windows rocks!
# exit

C:\Users\Justin>bash -c "sh" < rocks.sh
Error: 0x80070057

C:\Users\Justin>echo "./rocks.sh" | bash -c "sh"
Error: 0x80070057

@RaeesBhatti
Copy link
Author

Can confirm. 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
@MadcowD
Copy link

MadcowD commented May 1, 2016

I've made a related issue in Bash on Windows. #312

@bitcrazed
Copy link
Contributor

Thanks for the issue report - this was fixed in Creators Update.

@justinhixson
Copy link

justinhixson commented Jun 23, 2017

Thank you so much for this! This has been my most anticipated feature for the Linux Subsystem since i first heard about it. I am enjoying it immensely, and can confirm that it now works exactly as one would imagine it would. Thanks again!!!!!

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