将数据传送到需要 TTY(终端)的 Linux 程序 [英] Piping data to Linux program which expects a TTY (terminal)

查看:30
本文介绍了将数据传送到需要 TTY(终端)的 Linux 程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Linux 中有一个程序,如果它的 stdin/stdout 不是 TTY(终端设备),它就会拒绝运行.是否有一个易于使用的工具可以创建 PTY,使用新创建的 TTY 启动程序,并将所有数据复制到 stdin/stdout?

I have a program in Linux which refuses to run if its stdin/stdout is not a TTY (terminal device). Is there an easy-to-use tool which will create a PTY, start the program with the newly created TTY, and copy all data over stdin/stdout?

用例不是交互式的,而是脚本化的.我正在寻找最轻量级的解决方案,最好不要创建 TCP 连接,并且不需要安装太多其他工具和库.

The use case is not interactive, but scripting. I'm looking for the most lightweight solution, preferably not creating TCP connections, and not requiring too many other tools and libraries to be installed.

推荐答案

unbuffer,expect 的一部分(sudo apt-get install expect-dev on Ubuntu Lucid),可以使程序误以为它已连接到 TTY.

unbuffer, part of expect (sudo apt-get install expect-dev on Ubuntu Lucid), can fool a program into thinking it's connected to a TTY.

$ tty 
/dev/pts/3
$ echo | tty 
not a tty
$ echo | unbuffer tty 
/dev/pts/11

这篇关于将数据传送到需要 TTY(终端)的 Linux 程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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