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
Based on Chris' solution, I came up with the following little helper function:
faketty() {
script -qfc "$(printf "%q " "$@")" /dev/null
}
The quirky looking printf
is necessary to correctly expand the script's arguments in $@
while protecting possibly quoted parts of the command (see example below).
Usage:
faketty
Example:
$ python -c "import sys; print sys.stdout.isatty()"
True
$ python -c "import sys; print sys.stdout.isatty()" | cat
False
$ faketty python -c "import sys; print sys.stdout.isatty()" | cat
True