Go to the previous, next section.

Subprocess Execution

Control Input or Output of a window by another filter process. Use with care!


Command: 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 already running (shell) and screen itself (window) is controlled by the filedescriptor 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 already running process. A colon (:) combines both.
User input will go to newcommand unless newcommand requests the old process' output (fdpats first character is `!' or `:') or a pipe symbol (`|') is added to the end of fdpat.
Invoking exec without arguments shows name and arguments of the currently running subprocess in this window.
When a subprocess is running the kill command will affect it instead of the window's process.
Refer to the postscript file `doc/fdpat.ps' for illustration of all 21 possible combinations. Each drawing shows the numbers 210 representing the three file descriptors of newcommand. The box marked `W' is usual pty that has the old process (shell) on its slave side. The box marked `P' is the secondary pty that now has screen at its master side.

Using Exec



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'.

!!stty 19200
exec!stty 19200
exec !.. stty 19200
Set the speed of the window's tty. If your stty command operates on stdout, then add another `!'. This is a useful command, when a screen window is directly connected to a serial line that needs to be configured.

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.

!: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.

Go to the previous, next section.