def redirect_std ( ) : stdin = sys . stdin stdout = sys . stdout if not sys . stdin . isatty ( ) : sys . stdin = open_raw ( "/dev/tty" , "r" , 0 ) if not sys . stdout . isatty ( ) : sys . stdout = open_raw ( "/dev/tty" , "w" , 0 ) return stdin , stdout
python redirect stdout and stdin subprocess
Connect stdin / stdout to controlling terminal even if the scripts input and output were redirected . This is useful in utilities based on termenu .
def redirect_std():
    """
    Connect stdin/stdout to controlling terminal even if the scripts input and output
    were redirected. This is useful in utilities based on termenu.
    """
    stdin = sys.stdin
    stdout = sys.stdout
    if not sys.stdin.isatty():
        sys.stdin = open_raw("/dev/tty", "r", 0)
    if not sys.stdout.isatty():
        sys.stdout = open_raw("/dev/tty", "w", 0)

    return stdin, stdout