Connect to byobu screen session and execute command?

You can directly attach to a previously detached byobu/screen session including the window:

byobu -r -p2

will reattach into window 2 (or a named one).

-X can send any command to a byobu/screen session and also works with the -p switch.

byobu -p2 -X stuff "uname -a $(echo -ne '\r')"

This will send a uname -a to the second (third actually) byobu window, the echo at the end sends a carriage return so the commands gets executed.


You can send a command to a particular screen window of a particular screen session without attaching to it.

screen -S sessionname -p windowname -X screencommand

The session name is set with the -S option when starting screen or the sessionname command; by default it's byobu with byobu. You can also use the screen PID after -S. You can set a window's name with the title command. You can also use the window number.

screen -S byobu -p 1 -X stuff 'ls
'