Stderr & stdout reversed when printed to screen

When working on the Standard Streams and File Descriptors lesson, I noticed that when there are two commands–one whose output goes to stdout and the other whose output goes to stderr–their output order isn’t necessarily the same as the order of the commands:

As you can see in the screenshot, I reproduced a slightly different version of what happens in the lesson on the DQ interface command line, and this is consistent with what I’ve seen on my own terminal.

I’ve done some digging around the internet and found that this seems to be fairly common. One explanation I found is that it has something to do with buffering: stdout is buffered while stderr is not, which I will take to mean that stdout is somehow delayed on its way to the screen, so stderr gets there first. Would this be right?

1 Like