问题
I would like a solution that allows me to detach a ncurses
app to a different terminal emulator window and view the output of standard commands like 'cout' in the current one - for debugging and such.
I've seen a lot of solutions that write to a file and use tail
but that seems quite hacky and slow. BTW. I have no idea where to even begin, I'm quite new with ncurses.
回答1:
First of all, ncurses uses standard out for it's output so simply using 'cout' will mix up the output. Typically you will want to use standard error ('cerr') instead for debugging and such.
If you don't want to use a simple file and tail
(which isn't slow unless your your application is extreme in some way) you can use a named pipe like this:
mkfifo debug-pipe
Then run your application in a new terminal (for example xterm) and redirect error output to the named pipe.
xterm -e "my-application 2> debug-pipe" &
And lastly dump the named pipe in the first terminal (or any terminal).
cat debug-pipe
(By the way, I think I understand what kind of solution you first imagined. If the second terminal emulator could just redirect the standard error to it's own standard error it would simply appear in the first terminal. It would be easy for a terminal emulator to do this, but as far as I know none has that option.)
回答2:
You can initialize curses in one of two ways:
using initscr (which uses the standard input/output), or
using newterm (which lets you specify which input/output to use)
For example, the ncurses test-program ditto uses newterm to open output displays on one or more xterm's. Here is a screenshot:
In principle, you could use the current terminal for input, and display ncurses output on another terminal (though offhand, I don't recall any useful programs which do this — only demos).
回答3:
Detaching and re-attaching any console session can be achieved using screen
or tmux
apps.
来源:https://stackoverflow.com/questions/41451030/get-output-from-ncurses-app-on-a-separate-terminal