我正在尝试做与“Detect if stdin is a terminal or pipe?”相反的事情。
我正在运行一个正在更改其输出格式的应用程序,因为它检测到 STDOUT 上的管道,我希望它认为它是一个交互式终端,以便在重定向时获得相同的输出。
我原以为将它包装在 expect
脚本中或在 PHP 中使用 proc_open()
就可以了,但事实并非如此。
有什么想法吗?
最佳答案
啊哈!
script
命令完成了我们想要的...
script --return --quiet -c "[executable string]" /dev/null
成功了!
Usage:
script [options] [file]
Make a typescript of a terminal session.
Options:
-a, --append append the output
-c, --command <command> run command rather than interactive shell
-e, --return return exit code of the child process
-f, --flush run flush after each write
--force use output file even when it is a link
-q, --quiet be quiet
-t[<file>], --timing[=<file>] output timing data to stderr or to FILE
-h, --help display this help
-V, --version display version
关于bash - 如何欺骗应用程序认为它的标准输出是终端,而不是管道,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1401002/