且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

捕获直接重定向到/dev/tty

更新时间:2022-05-10 03:13:31

我不太确定@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).