shelljs / shx

Portable Shell Commands for Node
MIT License
1.72k stars 44 forks source link

piping from cat seems broken #85

Closed pierrebeaucamp closed 7 years ago

pierrebeaucamp commented 7 years ago

Hey,

I noticed that a lot of output gets missing when I pipe from shx cat. However, shx cat by itself seems to work fine.

Example:

shx cat src/app/**/*.js > /tmp/output && wc /tmp/output
   15655   41088  460494 /tmp/output

shx cat src/app/**/*.js | wc
    2181    5902   65536

For comparison:

 cat src/app/**/*.js | wc
   15655   41088  460494

I'm running 0.1.4

pierrebeaucamp commented 7 years ago

Hm I think that's because shx exits before it wrote everything to stdout. This seems to be related: https://github.com/mochajs/mocha/issues/333

nfischer commented 7 years ago

I have a fix for this, based on the mocha solution. I'll upload later tonight. Thanks for reporting this and for doing great research on the issue!

Unfortunately, it meant rewriting our test setup a bit, so the diff is a little big. The tests themselves haven't changed in any way though.

This particular issue was difficult to write a test for, but I've verified on my local machine. If we really want a test, we can hack something together with shell.exec().

pierrebeaucamp commented 7 years ago

Thanks for the quick patch!

nfischer commented 7 years ago

@pierrebeaucamp my pleasure. Thanks again for your help in tracking down the source of the bug.

We should have a new shx release out shortly, once I get through some of the other issues.