[Python] How to create a terminal-like python pipe?

Discussão em 'Python' iniciado por Stack, Setembro 26, 2024.

  1. Stack

    Stack Membro Participativo

    Some programs emit colored text when their output is connected to a terminal, and non colored text when their output goes to a pipe.

    Is there a way in Python to open a pipe to a subprocess such that the subprocess will 'think' that it's outputs is connected to a terminal and will emit colored text?

    In my specific case, the a Python program that uses click.secho() for colored text output, and I believe that click uses os.isatty(fd) to determine if it's connected to a terminal.

    Continue reading...

Compartilhe esta Página