balena preload stdout redirection

Hello,

I have a Python script that is responsible for multiple operations, one of which is to update a base fleet image to the latest commit. I am therefore using the CLI preload command under the subprocess Python package, but only part of the output is redirected.

For example, if the image was already preloaded with the target commit, then the following output would appear in the shell console:

Building Docker preloader image. [========================] 100%
| Checking that the image is a writable file
| Finding a free tcp port
| Checking if the image is an edison zip archive
| Creating preloader container
/ Starting preloader container
| Fetching application <fleet_slug>
\ Reading image information
| Fetching application <fleet_id>
/ Cleaning up temporary files
Nothing new to preload. (BalenaError)

If redirecting the output of the balena preload message in bash directly, i.e. balena preload <img_file.img> --commit <commit_id> --fleet <fleet_slug> 2>&1 | tee test.log, the file contains only the following:

b'\n'
b'\x1b[1ABuilding Docker preloader image. [                        ] 0%\n'
b'\x1b[1A                                                              \n'
b'\x1b[1ABuilding Docker preloader image. [===                     ] 12%\n'
b'\x1b[1A                                                               \n'
b'\x1b[1ABuilding Docker preloader image. [======                  ] 25%\n'
b'\x1b[1A                                                               \n'
b'\x1b[1ABuilding Docker preloader image. [=========               ] 37%\n'
b'\x1b[1A                                                               \n'
b'\x1b[1ABuilding Docker preloader image. [============            ] 50%\n'
b'\x1b[1A                                                               \n'
b'\x1b[1ABuilding Docker preloader image. [===============         ] 62%\n'
b'\x1b[1A                                                               \n'
b'\x1b[1ABuilding Docker preloader image. [==================      ] 75%\n'
b'\x1b[1A                                                               \n'
b'\x1b[1ABuilding Docker preloader image. [=====================   ] 87%\n'
b'\x1b[1A                                                               \n'
b'\x1b[1ABuilding Docker preloader image. [========================] 100%\n'
b'\n'
b'\x1b[2K\x1b[1G\n'
b'\x1b[2K\x1b[1G\n'
b'\x1b[2K\x1b[1G\n'
b'\x1b[2K\x1b[1G\n'
b'\x1b[2K\x1b[1G\n'
b'\x1b[2K\x1b[1G\n'
b'\x1b[2K\x1b[1G\n'
b'\x1b[2K\x1b[1G\n'
b'\x1b[2K\x1b[1GNothing new to preload. (BalenaError)\n'
b'\n'

All the “Checking”, “Starting”, “Fetching”, etc. lines are missing.

Ultimately, my question is as follows: how is the output handled in the preload CLI command?

Thanks in advance for your reply.