How to redirect a program that writes to tty?
Try this: script -q -c ‘module help null’ /dev/null > aaa.txt This works in a shell script (non-interactively) using $ script –version script (util-linux-ng 2.16) You may also be able to use expect. Also see: Catching a direct redirect to /dev/tty.