Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When using .once -o, only last line remains #148

Closed
mjpieters opened this issue Jul 10, 2022 · 2 comments · Fixed by #168
Closed

When using .once -o, only last line remains #148

mjpieters opened this issue Jul 10, 2022 · 2 comments · Fixed by #168

Comments

@mjpieters
Copy link
Contributor

When using .once -o ..., only the last line of the next output remains in the file once that command has completed.

That's because the write_once() function is executed for each individual output line, and each time the output file is opened with a new open(**once_file) call. Because the -o sets the file mode to "w", the output file is truncated for each line, and so all preceding output is lost.

Either the write_once() should execute once_file["mode"] = "a" so further lines are appended instead of replacing the file, or the code should be refactored to work like the tee() command and keep a reference to the opened file for re-use until unset_once_if_written() is called (which would then close the file). With that second option, you could then also drop the written_to_once_file flag variable, because the opened file object would only exist if there had been output to write.

@amjith
Copy link
Member

amjith commented Jul 11, 2022

Good catch. I'll check the implementation to see if I can refactor it. Thanks for reporting the bug.

@mjpieters
Copy link
Contributor Author

Ping, is this still on your radar?

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 a pull request may close this issue.

2 participants