Redirecting STDOUT

Hello,
When i try exec:
ping 8.8.8.8 > file
ping process write to file continuously (saves line by line),

When a I try the same in docker:

docker run --name tt --rm -d mongo bash -c “/bin/ping 8.8.8.8 > /tmp/pingi”

the file /tmp/pingi is filled by 4096 kb portions

Is this normal behavior ?

regards, Olaf

Appendix:
It is depend on image ?
under image debian everything looks like ok

If you mean 4096-byte (4 KiB) chunks, yes, that seems pretty normal. (Writes to stdout and elsewhere can be buffered by the underlying library, and the default can be either “buffer up to the next newline” or “buffer in larger chunks” depending on whether stdout is a tty or not.)

I can think of a couple of differences between images (many are based on the Alpine distribution, which has a different libc; the specific ping(1) binary may or may not call setvbuf(3) or fflush(3)). Of course, Docker suggests all of the MongoDB images are Debian-based, so…?

2 Likes

Thank you for complete explanation,

I want to redirect both stdout and stderr of a process to a single file. How do I do that in Bash bluestacks?