捕获直接重定向到/dev/tty [英] Catching a direct redirect to /dev/tty

查看:131
本文介绍了捕获直接重定向到/dev/tty的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为一个将文本直接吐到/dev/tty的程序的应用程序控制器工作.

I'm working on an application controller for a program that is spitting text directly to /dev/tty.

这是一个生产应用程序控制器,必须能够捕获所有发送到终端的文本.通常,这不是问题.我们只需重定向stdout和stderr.这个特定的应用程序直接调用echo并将结果重定向到/dev/tty(echo "some text" > /dev/tty).通过我的应用程序控制器重定向无法捕获文本.

This is a production application controller that must be able to catch all text going to the terminal. Generally, this isn't a problem. We simply redirect stdout and stderr. This particular application is making direct calls to echo and redirecting the result to /dev/tty (echo "some text" > /dev/tty). Redirects via my application controller are failing to catch the text.

我确实有此应用程序的源代码,但是无法对其进行修改,也不再对其进行维护.关于如何捕获和/或丢弃输出的任何想法?

I do have the source for this application, but am not in a position to modify it, nor is it being maintained anymore. Any ideas on how to catch and/or throw away the output?

推荐答案

我不太确定@flolo提到的screen程序是否可以满足您的需求.可能可以,但是我不确定是否内置了日志记录功能,这似乎正是您所需要的.

I can't quite determine whether the screen program mentioned by @flolo will do what you need or not. It may, but I'm not sure whether there is a logging facility built in, which appears to be what you need.

可能已经有一个程序可以满足您的需要.我会提名 sudosh 作为可能.

There probably is a program out there already to do what you need. I'd nominate sudosh as a possibility.

如果最终需要编写自己的脚本,则可能需要使用伪tty(pty),并使应用程序控制器位于用户的实际终端连接与pty设备之间,以便在其中记录日志.无论您需要它来记录什么.那不是小事.您可以在Rochkind的"高级UNIX编程,第二版Edn "一书,毫无疑问是其他类似的书(Stevens的"UNIX环境中的高级编程"书很可能是候选书,但我没有副本可以证明这一点.)

If you end up needing to write your own, you'll probably need to use a pseudo-tty (pty) and have your application controller sit in between the user's real terminal connection and the the pty device, where it can log whatever you need it to log. That's not trivial. You can find information about this in Rochkind's "Advanced UNIX Programming, 2nd Edn" book, and no doubt other similar books (Stevens' "Advanced Programming in the UNIX Environment" book is a likely candidate, but I don't have a copy to verify that).

这篇关于捕获直接重定向到/dev/tty的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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