I know this article is for Windows, but if you're wondering if there's a way to do this on Linux, there is:
https://github.com/nelhage/reptyr
https://github.com/crigler/dtach
Is there a way to read from present tty?
In practice: I boot into tty and manually start the graphical session (Wayland/Sway). I occasionally get (non-Sway) warnings when I return to tty (eg close the window manager). But the output is always scuffed, so I can't read the whole log. The lines get printed on top of each other or something.
Is there a way to read everything from tty, from within the tty?
Neither of the methods below work, because the warnings/errors aren't produced by Sway itself, but some other OS module/component.
$ sway |& tee /tmp/sway.log
$ tail -f /tmp/sway.log
This prompted me to ask the crowd about a similar use-case of editing your command line as it's already running your command
vxworks 6.x:
(one login session, say over serial)
-> ioTaskStdGet 0, 1
value = 3 = 0x3
-> taskIdSelf
value = 13600784 = 0xcf8810
(another session, say over telnet) -> ioTaskStdSet 0xcf8810, 1, 0x9
value = 0 = 0x0
(first session ie SERIAL) -> printf "foo\n"
-> taskIdSelf
-> i
(otherone eg TELNET) -> foo
value = 4 = 0x4
value = 13600784 = 0xcf8810
NAME ENTRY TID PRI STATUS PC SP ERRNO DELAY
---------- ------------ -------- --- ---------- -------- -------- ------- -----
...
teeheeheehaw!I assume roughly the same caveats would apply, though? Buffering might be set wrong (and have no mechanism to be updated because the program never checks again), etc.
Thanks, links saved.
Then there is this method, but I guess that article refers to no redirection output.
If in background or via cron, I always redirect. But this is for UN*X type systems with a tail that supports '-f'
$ prog > /tmp/log.txt 2>&1 &
Then
$ tail -f /tmp/log.txt
Just so happens, I actually used this the other day for a long running process on OpenBSD :)
Here's my method using GDB from many years ago: https://gist.github.com/zaius/782263