如何诱使应用程序认为其标准输出是终端而不是管道 [英] How to trick an application into thinking its stdout is a terminal, not a pipe

查看:73
本文介绍了如何诱使应用程序认为其标准输出是终端而不是管道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试与"

我正在运行一个正在更改其输出格式的应用程序,因为它检测到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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆