Set a terminal type for dumping tools when their output is not a terminal - #1018
Merged
Conversation
…ng TERM
When the Linux tool-output console is active, a dumping tool's stdout is a pipe
instead of a terminal. Some tools (notably Aaru 5) query the console width while
drawing progress; on a non-terminal that width can only come from the
TERM/terminfo fallback, and when TERM is unset it returns 0, so the tool does
`new string(' ', width - 1)` and throws before the first read.
Apps launched from a GNOME session inherit no TERM (measured on GNOME Shell 50.1:
menu launches get no TERM), so Aaru 5 aborts there; KDE happens to set TERM=dumb,
which carries a terminfo width, so it works. Set TERM to a type with a known
width when the environment has none, only on the redirected path, so a tool
always gets a usable width. A real terminal's TERM is left untouched.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
A tool started with UseShellExecute inherits the frontend's stdout, so MPF.CLI run with its output redirected -- from a script, a cron job, or a service -- hands the tool a non-terminal as well, even though nothing is redirected here. The previous commit only covered the case where an output sink is attached, so the CLI kept aborting. Measured on a Plextor PX-760A with an audio CD and Aaru 5.4.2 as the dumping program. With output redirected and TERM unset, MPF.CLI produced a zero-byte image and Aaru threw ArgumentOutOfRangeException from Aaru.Progress.ClearCurrentConsoleLine(); with this change the same invocation dumps normally. Running from a real terminal is unaffected, and a terminal that already provides TERM is still left alone. The added check is limited to .NET 5 and newer on non-Windows: TERM carries no meaning on Windows, and an environment entry cannot be combined with UseShellExecute there. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Contributor
Author
|
I've expanded this PR. The original commit fixed the GUI console path (#998); I then found the same Aaru 5 crash on the Generated with Claude Opus 4.8. |
mnadareski
approved these changes
Jul 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Aaru 5 queries the console width (
Console.WindowWidth) while drawing progress. When its standard output is not a terminal, that width can only come from theTERM/terminfo fallback, and whenTERMis unset it comes back as0. Aaru 5 then evaluatesnew string(' ', width - 1)and throwsArgumentOutOfRangeExceptionon the very first progress update, before it reads a single sector.MPF hands Aaru 5 a non-terminal stdout in two independent situations:
MPF.CLIlaunches the tool withUseShellExecute = true, so the tool inheritsMPF.CLI's own stdout. WhenMPF.CLIitself runs without a terminal (a script, a service, cron, ormpf-cli … > log), the tool inherits that non-terminal. This path predates Add live tool output console for the Linux GUI #998 and is not specific to the GUI.Whether it bites also depends on the environment's
TERM:TERMseen by the tooldumb(has a terminfo width)xtermetc.So from GNOME — or any environment that does not export
TERM, including non-interactive service/cron contexts — Aaru 5 cannot dump at all, while the same build works from KDE or a terminal.Fix
When the tool's stdout will not be a terminal and the environment has no
TERM, setTERMto a type with a known width. This covers both the redirected (GUI) path and the inherited-output (CLI) path. A real terminal'sTERMis left untouched. The inherited-output check is limited to .NET 5+ on non-Windows:TERMis meaningless on Windows, and there an environment entry cannot be combined withUseShellExecute.Testing
Measured on real hardware (Plextor PX-760A, audio CD) in a clean VM, driving the real
BaseExecutionContext.ExecuteInternalProgrampath withTERMunset (the GNOME / service condition). Images are time-boxed, so sizes are not comparable between tools:TERMunset, no terminal)ArgumentOutOfRangeException, no imageredumperand DiscImageCreator are native tools that do not use the managed console-width API, and they are unchanged by this PR.--verbose True media dump …); Aaru 6 rejects it at parse time (Unexpected option 'verbose'), so it never reaches this code. Mentioned only for completeness.MPF.CLIat the commit just before my first contribution and reproduced the identical crash (ArgumentOutOfRangeException→Aaru.Progress.ClearCurrentConsoleLine()) under the same condition, and confirmed it dumps withTERM=xterm. This change does not introduce the CLI behavior; it fixes it.TargetFrameworksset (net20 … net10.0) with no warnings;MPF.ExecutionContexts.Test615 passed andMPF.Frontend.Test562 passed.Prepared with AI assistance (Claude Opus 4.8) and reviewed before submission.