How do I flush stdout in a `%%script bash` cell?

How do I flush stdout in a %%script bash cell in a Jupyter notebook (Google Colab, actually)?

I have some long-running script cells, and I like to see the results as they are coming out, not waiting for the whole cell to finish.

I thought this sounded like what you may be after; however, it is written for Windows. Note the chcp stuff.
However, I note in the original post of that thread that use of ! causes it to show instantly in Google Colab. But that was combined with Python and may not hold true for pure bash?

1 Like

You are correct, ! works as expected, but %%script cells don’t.

!echo hi ; sleep 5
%%script bash
echo hi ; sleep 5

Is that Windows solution portable to Linux?

You may want to add an @ with the names in that thread/post to that question to help them see this because I wouldn’t know where to begin on that.

Unfortunately @NightMachinary reports that their IP address is blocked from further contributions on Discourse, so they have moved the discussion onto GitHub. Please add more replies here: [FR/QST] How do I flush stdout in a `%%script bash` cell? · Issue #6277 · jupyter/notebook · GitHub

1 Like