我正在运行一个正在更改其输出格式的应用程序,因为它检测到STDOUT上的管道,并且我希望它认为它是一个交互式终端,以便在重定向时获得相同的输出.
I'm running an application that's changing its output format because it detects a pipe on STDOUT, and I want it to think that it's an interactive terminal so that I get the same output when redirecting.
我当时想将其包装在expect
脚本中或在PHP中使用proc_open()
都可以,但事实并非如此.
I was thinking that wrapping it in an expect
script or using a proc_open()
in PHP would do it, but it doesn't.
那里有什么主意吗?
推荐答案
啊哈!
script
命令完成了我们想要的...
The script
command does what we want...
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
这篇关于如何诱使应用程序认为其标准输出是终端而不是管道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!