Skip to content

Enable redirecting non-interactive run console output to file#317

Merged
tfoote merged 1 commit intomainfrom
console_to_file
Feb 1, 2025
Merged

Enable redirecting non-interactive run console output to file#317
tfoote merged 1 commit intomainfrom
console_to_file

Conversation

@tfoote
Copy link
Collaborator

@tfoote tfoote commented Jan 30, 2025

No description provided.

tfoote added a commit to opencv/bpc that referenced this pull request Jan 30, 2025
Comment on lines +404 to +410
with open(console_output_file, 'a') if console_output_file else nullcontext() as consoleout_fh:
if console_output_file:
print(f"Logging output to file {console_output_file}")
print("Executing command: ")
print(cmd)
p = subprocess.run(shlex.split(cmd), check=True, stdout=consoleout_fh if console_output_file else None, stderr=subprocess.STDOUT)
return p.returncode
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was my first time seeing nullcontext. I'm not sure if I love it but I juggled a few different methods for handling this and all were more error prone than using the context manager unconditionally.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, i did a bunch of searching on it and it eventually seemed like the best way to not have two branches of almost duplicate code.

@tfoote tfoote merged commit 66fe159 into main Feb 1, 2025
8 checks passed
@tfoote tfoote deleted the console_to_file branch February 1, 2025 01:34
AllProAi pushed a commit to AllProAi/bpc that referenced this pull request Mar 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants