bash - 如何欺骗应用程序认为它的标准输出是终端,而不是管道

标签 bash terminal pipe stdin

我正在尝试做与“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/

相关文章:

c - 将视频输出到文件和管道 : simultaneously using FFmpeg Libav

bash - 为什么运行docker容器时没有执行 `~/.bashrc`?

java - 异常线程错误

ios - 如何通过SSH访问iOS模拟器文件系统?

c - pselect 通知两个管道读端文件描述符,即使只有一个写端被写入

c++ - Boost asio 与标准输入混淆?

bash - 有人可以解释/给出这个 shell 参数替换的详细信息吗? ${cfg+-f "$cfg"}

bash - [[ 复合命令中未设置的参数是否预期为 bash 中的空字符串?

linux - 第一次替换后停止 sed

单行Java终端程序输出