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

查看:314
本文介绍了将数据传输到需要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)(在Ubuntu Lucid中为sudo apt-get install expect-dev)的一部分,可能使程序误以为它已连接到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天全站免登陆