The exec statement
Synopsis
exec <shell command to execute>
Behavior
The exec statement runs the command specified as an argument using a bash shell in a managed fashion. The command is specified using a string which may be in double quotes, single quotes or triple quotes. Variables will be evaluated and expanded even when surrounded by single quotes. Single quotes inside double quotes are passed through to the underlying shell and thus can be used to pass values that may contain spaces.
The exec statement blocks until the specified command returns. See the async statement for an alternative that launches the process in the background and returns immediately.
Long commands that are passed to exec can be specified over multiple lines by using triple quotes. Bpipe automatically removes newlines from commands so that you do not need to worry about it.
An exec statement will often be embedded in a produce, filter or transform block to specify and manage the outputs of the command.
Logging
All commands executed via exec are automatically added to the command history for the run.
Failure
If the command fails or is interrupted (by Ctrl-C or kill), the pipeline will be automatically terminated. Any outputs specified as generated by the stage running the exec command will be marked as dirty and moved to the local bpipe trash folder.
Examples
Example 1 - echo
exec "echo 'Hello World'"
Example 2 - Run Samtools
exec """
samtools mpileup -uf genome.fa $input | bcftools view -bvcg - > $output
"""
Example 3 - Using Multiple Lines This example executes the same command as Example 2, but formats it over multiple lines.
exec """
samtools mpileup
-u
-f genome.fa
$input
|
bcftools view
-b
-v
-c
-g - > $output
"""