Console output from bash command executed with wsl getting truncated when redirected to a file

Viewed 318

I'm attempting to use wsl to execute a bash command from powershell/cmd and capture the output to a file.

When I run wsl -e cat /etc/services the full contents of the file appears correctly in the console.

However, if I run wsl -e cat /etc/services > foo.txt the contents of the foo.txt only contain the first ~ 4k characters from the output. If I run the same command in wsl bash, the foo.txt contains the full content I would expect. I've tried this with a number of wsl commands, and the cutoff point always seems to be about 4k characters. I've also tried wsl -- cat /etc/services > foo.txt with the same results.

Does anyone know why the truncation is happening? More importantly, how do I run a command with wsl and capture the output to a file?

0 Answers
Related