Skip to content
Discussions/App Development/Daml Sandbox (2.2.0) output redirectionForum ↗

Daml Sandbox (2.2.0) output redirection

App Development7 posts420 views2 likesLast activity Jul 2022
GA
gaborhOP
Jul 2022

I tried to execute:

daml sandbox &> log.log &

I expected to see log lines in log.log (e.g. Starting Canton sandbox.) but there is nothing even after minutes.

Is this the correct behaviour and if yes why?

CO
cocreature
Jul 2022

The issue here is buffering. Writing to stdout in a terminal usually defaults to line buffering so you see every line as soon as it is written. However, writing to a file usually is block buffered meaning that things only get written to the file once a full block is full.

In your example, that never happens so you don’t see any output. Note that it will be written once you kill sandbox (gracefully via SIGTERM not SIGKILL). So it’s not that the output isn’t written it’s just not flushed to the file because the block is not full.

I think it would be reasonable to say that we should always use line buffering for this.

In the meantime, you can use unbuffer to work around it:

unbuffer daml sandbox > log.log
GA
gaborh
Jul 2022

Thank you, this makes sense.

Just a note: unbuffer is in the expect package (at least on Ubuntu) command-not-found.com – unbuffer

By the way, I (obviously) had the same problem with Python / subprocess / Popen (“no output on process.stdout”, reading from there blocks forever :slight_smile: I wonder whether there is a better solution for that case than using unbuffer.

CO
cocreature
Jul 2022

You might be able to somehow disable buffering from within Python, i.e., somehow replicate what unbuffer is doing but I’m not familiar with the details there.

CO
cocreature
Jul 2022

Having read the code of unbuffer I do not recommend trying to replicate it :slight_smile:

CO
cocreature
Jul 2022

I opened Assistant/daml-helper should always line-buffer · Issue #14415 · digital-asset/daml · GitHub to switch to line buffering our code which would remove the need for unbuffer or similar workarounds.

GA
gaborh
Jul 2022

To be honest, that was my guess that it’s a bit more complex than one would like.

← Back to Discussions