If I remember correctly the issues I had when asking the question, I was not able to make a pure Nim solution work on windows giving back control to stdout (I suspect yours might not work on windows, I will try). Instead the solution by @clonk, although in principle should be only posix compatible, works perfectly on my windows 10.
Regarding avoiding the passage from a file, I did not find a way to do it with streams, I too would be interested in a solution (I am currently using package tempfile to create a temporary file).
