You can't do that in classic tex, but luatex gives you Lua access.
Terminal output ending in "hello world"
This is LuaHBTeX, Version 1.17.0 (TeX Live 2023)
restricted system commands enabled.
(./ee276.tex
LaTeX2e <2023-06-01> patch level 1
L3 programming layer <2023-10-23>
(/usr/local/texlive/2023/texmf-dist/tex/latex/base/article.cls
Document Class: article 2023/05/17 v1.4n Standard LaTeX document class
(/usr/local/texlive/2023/texmf-dist/tex/latex/base/size10.clo))
(/usr/local/texlive/2023/texmf-dist/tex/latex/l3backend/l3backend-luatex.def)
(./ee276.aux) (/usr/local/texlive/2023/texmf-dist/tex/latex/base/ts1cmr.fd)
[1{/usr/local/texlive/2023/texmf-var/fonts/map/pdftex/updmap/pdftex.map}]
(./ee276.aux))</usr/local/texlive/2023/texmf-dist/fonts/opentype/public/lm/lmro
man10-regular.otf>
hello world
From
\documentclass{article}
\directlua{
luatexbase.add_to_callback('stop_run',
function ()
texio.write("\string\n\string\n hello world\string\n")
end,
"final message"
)
}
\begin{document}
aaa
\end{document}
As seen above, stop_run callback replaces the usual printing of statistics. If you replace stop_run by wrapup_run then it comes after the usual statistics are printed
The documentation of this callback is, in full
This callback is called after the pdf and log files are closed. Use it at your own risk.
But I think it's safe enough here
$ lualatex ee276
This is LuaHBTeX, Version 1.17.0 (TeX Live 2023)
restricted system commands enabled.
(./ee276.tex
LaTeX2e <2023-06-01> patch level 1
L3 programming layer <2023-10-23>
(/usr/local/texlive/2023/texmf-dist/tex/latex/base/article.cls
Document Class: article 2023/05/17 v1.4n Standard LaTeX document class
(/usr/local/texlive/2023/texmf-dist/tex/latex/base/size10.clo))
(/usr/local/texlive/2023/texmf-dist/tex/latex/l3backend/l3backend-luatex.def)
(./ee276.aux) (/usr/local/texlive/2023/texmf-dist/tex/latex/base/ts1cmr.fd)
[1{/usr/local/texlive/2023/texmf-var/fonts/map/pdftex/updmap/pdftex.map}]
(./ee276.aux))
406 words of node memory still in use:
3 hlist, 1 vlist, 1 rule, 2 glue, 3 kern, 1 glyph, 4 attribute, 48 glue_spec
, 4 attribute_list, 1 write nodes
avail lists: 2:22,3:4,4:1,5:22,6:2,7:34,9:18
</usr/local/texlive/2023/texmf-dist/fonts/opentype/public/lm/lmroman10-regular.
otf>
Output written on ee276.pdf (1 page, 2613 bytes).
Transcript written on ee276.log.
hello world