Use:
tmux split-window "shell command"
The split-window
command has the following syntax:
split-window [-dhvP] [-c start-directory] [-l size | -p percentage] [-t
target-pane] [shell-command] [-F format]
(from man tmux
, section "Windows and Panes"). Note that the order is important - the command has to come after any of those preceding options that appear, and it has to be a single argument, so you need to quote it if it has spaces.
For commands like ping -c
that terminate quickly, you can set the remain-on-exit
option first:
tmux set-option remain-on-exit on
tmux split-window 'ping -c 3 127.0.0.1'
The pane will remain open after ping
finishes, but be marked "dead" until you close it manually.
If you don't want to change the overall options, there is another approach. The command is run with sh -c
, and you can exploit that to make the window stay alive at the end:
tmux split-window 'ping -c 3 127.0.0.1 ; read'
Here you use the shell read
command to wait for a user-input newline after the main command has finished. In this case, the command output will remain until you press Enter in the pane, and then it will automatically close.
; cat
instead, so I have to explicitly hit<ctrl-c>
to kill the window. I often hit<enter>
to break up output, soread
isn't enough. – ddrscott Dec 21 '19 at 13:40