Преглед изворни кода

use socat to create a pseudo-tty so that paging/colors more likely to work

Daniel Sheffield пре 3 месеци
родитељ
комит
1b0ad1303b
1 измењених фајлова са 9 додато и 6 уклоњено
  1. 9 6
      capture.sh

+ 9 - 6
capture.sh

@@ -18,6 +18,7 @@ LOG_DIR="$LOG_ROOT"/"$PROG"/"$SUBPROG"/"$TIMESTAMP"
 
 mkdir -p "$LOG_DIR"
 
+PTY="$LOG_DIR"/pty
 OUT="$LOG_DIR"/stdout
 ERR="$LOG_DIR"/stderr
 DAT="$LOG_DIR"/dat
@@ -29,14 +30,16 @@ info(){
 $CMD
 status=$?
 EOF
-	exec 2>&-
-	exec 1>&-
-	wait "$err_pid" "$out_pid"
+	exec 1>&- 2>&-
+	kill "$socat_out"
+	wait
 }
 
 trap 'info' EXIT
+tty="$(tty)"
+socat PTY,rawer,link="$PTY" EXEC:"tee -a \"$DAT\" \"$OUT\" \"$tty\"" &
+socat_out="$!"
+while ! [ -e "$PTY" ]; do sleep 0.1; done
 exec 2> >(tee -a "$DAT" "$ERR")
-err_pid="$!"
-exec 1> >(tee -a "$DAT" "$OUT")
-out_pid="$!"
+exec 1> "$PTY"
 "$@"