Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Piping to WSL?

May
13,418
190
This works reliably.

Code:
v:\> (do i=100 to 1 by -1 ( echo %i %@repeat[x,36] )) | wsl sort -n | tail /n 5
96 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
97 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
98 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
99 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
100 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

If I make the lines 1 character longer it never works correctly, often producing no output at all.

Code:
v:\> (do i=100 to 1 by -1 ( echo %i %@repeat[x,37] )) | wsl sort -n | tail /n 5
94 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
95 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
96 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
97 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
98 xxxxxxxxxxxxxxxxxxxxxxxxxxxx

v:\> (do i=100 to 1 by -1 ( echo %i %@repeat[x,37] )) | wsl sort -n | tail /n 5

v:\>
 
This seems to depend (in a not very predictable way) on what command follows the last pipe. If I do this, TAIL sees 41 lines of output (occasionally none).

Code:
(do i=100 to 1 by -1 ( echo %i %@repeat[x,97] )) | wsl sort -n | tail

The same is true of HEAD, TPIPE (/head, /tail, /grep), DO x in @con, and Windows's FIND.EXE.

OTOH, these reliably see all 100 lines of output: FINDSTR.EXE, SORT.EXE, LC (a line-count plugin of my own).

And it can be quite erratic.

Code:
d:\tc26\library> (do i=100 to 1 by -1 ( echo %i %@repeat[x,77] )) | wsl sort -n | find /c /v ""
100

d:\tc26\library> (do i=100 to 1 by -1 ( echo %i %@repeat[x,77] )) | wsl sort -n | find /c /v ""
51
 
After more experimenting ... it's not piping to wsl, it's piping wsl's output to somethng else ... very unreliable. I get screwy results in CMD too. I doubt TCC can do anything about it.

Fortunately, for my purposes, long sequences of pipes can be done completely in (one) wsl.

Code:
v:\> (do i=100 to 1 by -1 ( echo %i %@repeat[x,40] )) | ( wsl sort -n ^| tail -n 3 )
98 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
99 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
100 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

v:\> (do i=100 to 1 by -1 ( echo %i %@repeat[x,40] )) | ( wsl sort -n ^| tail -n 3 ^| wc -l )
3
 
My guess would be the way console stuff is done for WSL is the issue. There is something special about the way stdin/out/err works in WSL so that things like ssh et. al. work correctly. I vaguely remember reading about that in the "What's new in WSL2" description.
 
I would say "you are using WSL wrong". For your purposes, something like Cygwin of UNIX utils for Windows would fit better. Or just do everything in WSL.
 
Back
Top
[FOX] Ultimate Translator
Translate