Site Tools


Default Keybindings



  • exec [[fdpat] newcommand [args ]]


Run a unix subprocess (specified by an executable path newcommand and its optional arguments) in the current window. The flow of data between newcommand's stdin/stdout/stderr, the process originally started in the window (let us call it “application-process”) and screen itself (window) is controlled by the file descriptor pattern fdpat. This pattern is basically a three character sequence representing stdin, stdout and stderr of newcommand. A dot (.) connects the file descriptor to screen. An exclamation mark (!) causes the file descriptor to be connected to the application-process. A colon (:) combines both. User input will go to newcommand unless newcommand receives the application-process' output (fdpat's first character is ! or :) or a pipe symbol (|) is added (as a fourth character) to the end of fdpat.

Invoking exec without arguments shows name and arguments of the currently running subprocess in this window. Only one subprocess a time can be running in each window. When a subprocess is running the kill command will affect it instead of the window's process.

Refer to the postscript file for a confusing illustration of all 21 possible combinations. Each drawing shows the digits 2,1,0 representing the three file descriptors of newcommand. The box marked “W” is the usual pty that has the application-process on its slave side. The box marked “P” is the secondary pty that now has screen at its master side.


Whitespace between the word exec and fdpat and the command can be omitted. Trailing dots and a fdpat consisting only of dots can be omitted. A simple “|” is synonymous for the pattern “!..|”; the word exec can be omitted here and can always be replaced by “!”.


exec ... /bin/sh
exec /bin/sh

Creates another shell in the same window, while the original shell is still running. Output of both shells is displayed and user input is sent to the new /bin/sh.

exec !.. stty 19200
exec ! stty 19200
!!stty 19200

Set the speed of the window's tty. If your stty command operates on stdout, then add another “!”.

exec !..| less

This adds a pager to the window output. The special character | is needed to give the user control over the pager although it gets its input from the window's process. This works, because less listens on stderr (a behavior that screen would not expect without the |) when its stdin is not a tty. Less versions newer than 177 fail miserably here; good old pg still works.

!:sed -n s/.*Error.*/\007/p

Sends window output to both the user and the sed command. The sed inserts an additional bell character (oct. 007) to the window output seen by screen. This will cause “Bell in window x” messages, whenever the string “Error” appears in the window.

See Also

User Tools