Skip to content

[#2514] Flush out/err PrintWriters after CommandLine.execute - #2527

Open
kalayciburak wants to merge 1 commit into
remkop:mainfrom
kalayciburak:fix/2514-flush-out-err-after-execute
Open

[#2514] Flush out/err PrintWriters after CommandLine.execute#2527
kalayciburak wants to merge 1 commit into
remkop:mainfrom
kalayciburak:fix/2514-flush-out-err-after-execute

Conversation

@kalayciburak

Copy link
Copy Markdown

Summary

CommandLine.execute did not flush out/err after the command finished. PrintWriter autoFlush only applies to println/printf/format, so data written with print() could stay buffered and disappear when the JVM exits right after execute().

This change flushes the root command and every parsed command-line's writers in a finally block after execute.

Fixes #2514

Test plan

  • ./gradlew :test --tests picocli.ExecuteTest.testExecuteFlushesOutAfterPrintWithoutNewline --tests picocli.ExecuteTest.testExecuteFlushesErrAfterPrintWithoutNewline (RED before fix, GREEN after)
  • ./gradlew :test --tests picocli.ExecuteTest — 86/86 GREEN
  • ./gradlew :test — 2283 tests, 0 failures, 32 skipped

print() does not trigger autoFlush on PrintWriter. Flush the root and
parsed command writers in a finally block so buffered output is not lost
when the JVM exits immediately after execute().
@kalayciburak
kalayciburak force-pushed the fix/2514-flush-out-err-after-execute branch from 200aaaa to 8e6ce5e Compare August 16, 2026 09:43
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.

execute() does not flush out/err PrintWriters after command execution

1 participant