You used tmux send-keys to "type" commands into the interactive shells running in the tmux panes. Each shell behaved like any other interactive shell: it echoed (or let the line discipline echo) what you typed, it printed a prompt each time a command completed.
This is a very cumbersome way to run something in tmux.
The right way to run something in tmux is to give some shell code directly to new-session, new-window, split-window, respawn-window or respawn-pane tmux command. E.g.:
tmux split-window 'echo foo; sleep 5'Depending on the settings, the new pane will or will not be destroyed when sleep 5 exits. See "Terminating the tmux session" in this answer of mine.
It seems you don't really need to run anything; you just want ttys that will display messages from your program. To create a pane that does not disappear by itself, run tail -f /dev/null in it. To know the tty of a pane, ask tmux about #{pane_tty} of the pane.
I do not know C++. This is how you would do this in a shell:
# create a new tmux session with two panespane1="$(tmux new-session -d -s foo -PF '#{pane_id}''tail -f /dev/null')"pane2="$(tmux split-window -t foo -PF '#{pane_id}''tail -f /dev/null')"# get ttys of the panestty1="$(tmux display-message -p -t "$pane1" '#{pane_tty}')"tty2="$(tmux display-message -p -t "$pane2" '#{pane_tty}')"Use tmux attach-session -t foo in a separate terminal to see the two panes.
At this point you can print to the panes from the original shell:
date >"$tty1"echo foo >"$tty2"echo bar | tee "$tty1" "$tty2"In many cases it makes sense to open each tty once and just use the descriptor later on:
exec 3>"$tty1" 4>"$tty2"echo baz >&3uname >&4echo qux >&3or even redirect the stdout of the entire shell (exec >"$tty1"), so every future child will inherit it by default; this may be troublesome in an interactive shell, but useful in a shell script.
Finally, when the ttys are no longer needed, close the descriptors and kill the panes or the whole session at once:
exec 3>&- 4>&-# tmux kill-pane -t "$pane1"# tmux kill-pane -t "$pane2"# We want to kill the whole session at once, so the above commands# have been commented out. We could use them though.tmux kill-session -t foo# There is also kill-window.As I said, I don't know C++; you need to port this procedure by yourself. The point is you shall not use interactive shells and tmux send-keys. Set up tmux session(s), window(s) and panes, query tmux for relevant ttys, open the ttys from your program and print to them directly. At the end kill the tmux panes or window(s) or session(s) if this is what you want.