diff --git a/run_pipeline.sh b/run_pipeline.sh
index ad6a528bddbe1902b1f6d55fce5c46b625e6e272..a70d0abb301221946571b84487e16f02a25cbbf9 100755
--- a/run_pipeline.sh
+++ b/run_pipeline.sh
@@ -68,7 +68,13 @@ then
 else
     error_exit "Pipeline configuration file ${configfile} not found."
 fi
-echo ${cmd}
-eval ${cmd} || error_exit "${cmd} failed"
+
+# Determine the output directory and where to log the pipeline
+output_dir=$(grep "output_dir" "${configfile}" | mawk '{print $NF}' | sed 's/,$//' | sed 's/"//g')
+mkdir -p ${output_dir}
+log_base="${output_dir}/$(date +"%d%m%y_%Hh%Mm")"
+echo ${cmd} > ${log_base}.log
+# https://stackoverflow.com/a/692407/1878788
+eval ${cmd} > >(tee -a ${log_base}.log) 2> >(tee -a ${log_base}.err >&2) || error_exit "${cmd} failed"
 
 exit 0