How to trick an application into thinking its stdout is a terminal, not a pipe

前端 未结 9 1598
梦如初夏
梦如初夏 2020-11-22 11:58

I\'m trying to do the opposite of \"Detect if stdin is a terminal or pipe?\".

I\'m running an application that\'s changing its output format because it detects a pip

9条回答
  •  暖寄归人
    2020-11-22 12:35

    There's also a pty program included in the sample code of the book "Advanced Programming in the UNIX Environment, Second Edition"!

    Here's how to compile pty on Mac OS X:

    man 4 pty  #  pty -- pseudo terminal driver
    
    open http://en.wikipedia.org/wiki/Pseudo_terminal
    
    # Advanced Programming in the UNIX Environment, Second Edition
    open http://www.apuebook.com
    
    cd ~/Desktop
    
    curl -L -O http://www.apuebook.com/src.tar.gz
    
    tar -xzf src.tar.gz
    
    cd apue.2e
    
    wkdir="${HOME}/Desktop/apue.2e"
    
    sed -E -i "" "s|^WKDIR=.*|WKDIR=${wkdir}|" ~/Desktop/apue.2e/Make.defines.macos
    
    echo '#undef _POSIX_C_SOURCE' >> ~/Desktop/apue.2e/include/apue.h
    
    str='#include   '
    printf '%s\n' H 1i "$str" . wq | ed -s calld/loop.c
    
    str='
    #undef _POSIX_C_SOURCE
    #include 
    '
    printf '%s\n' H 1i "$str" . wq | ed -s file/devrdev.c
    
    str='
    #include 
    #include 
    '
    printf '%s\n' H 1i "$str" . wq | ed -s termios/winch.c
    
    make
    
    ~/Desktop/apue.2e/pty/pty ls -ld *
    

提交回复
热议问题