How to intercept transparently stdin/out/err
问题 I would like to catch all the inputs and output of a commandline program (namely, GDB, but currently changed to ls or cat for simplicity) and redirect it into a file, for later analysis. I couldn't get anything close to working, but I can't understand what's wrong. Here is my last attempt: #!/usr/bin/env python2 import subprocess import sys import select import os def get_pipe(): fd_r, fd_w = os.pipe() return os.fdopen(fd_r, "r"), os.fdopen(fd_w, "w") out_r, out_w = get_pipe() err_r, err_w =