xmos / xscope_fileio

FileIO interface over xscope
Other
2 stars 10 forks source link

Add support to optionally redirect stdout into a file #14

Closed shuchitak closed 2 years ago

shuchitak commented 2 years ago

This PR contains a set of changes to get stdout out of run_on_target() call.

The caller of run_on_target() can now optionally provide the stdout=xyz option and the subprocess will redirect the output into that. This is needed in cases where the caller of run_on_target() needs the stdout output for further processing. contextlib.redirect_stdout() that used to work okay with sh was earlier used to directly read stdout but it doesn't work with subprocess, so the caller has to explicitly pass in a file to run_on_target() to get the stdout output.

If no stdout=xyz argument is provided to run_on_target(), subprocess.Popen() runs with default stdout which is stdout=None and in this case prints can be seen being printed realtime which is important when running and debugging a module.