The answers by other users are right - exec &>$outfile
or exec &>$outfifo
or exec &>$another_tty
is what you need to do & is the correct way.
However, if you have already started the scripts, then there is a workaround that you can use. I had written this script to redirect the stdout
/stderr
of any running process to another file/terminal.
$ cat redirect_terminal
#!/bin/bash
PID=$1
stdout=$2
stderr=${3:-$2}
if [ -e "/proc/$PID" ]; then
gdb -q -n -p $PID <<EOF >/dev/null
p dup2(open("$stdout",1),1)
p dup2(open("$stderr",1),2)
detach
quit
EOF
else
echo No such PID : $PID
fi
Sample usage:
./redirect_terminal 1234 /dev/pts/16
Where,
1234
is the PID of the script process.
/dev/pts/16
is another terminal opened separately.
Note that this updated stdout/stderr will not be inherited to the already running children of that process.