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

前端 未结 9 1471
梦如初夏
梦如初夏 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:28

    Referring previous answer, on Mac OS X, "script" can be used like below...

    script -q /dev/null commands...
    

    But, because it may replace "\n" with "\r\n" on the stdout, you may also need script like this:

    script -q /dev/null commands... | perl -pe 's/\r\n/\n/g'
    

    If there are some pipe between these commands, you need to flush stdout. for example:

    script -q /dev/null commands... | ruby -ne 'print "....\n";STDOUT.flush' |  perl -pe 's/\r\n/\n/g'
    

提交回复
热议问题