将数据管道到需要TTY(终端)的Linux程序

时间:2022-05-11 10:21:04

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?

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

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.

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

1 个解决方案

#1


26  

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.

unbuffer,期待的一部分(Ubuntu Lucid上的sudo apt-get install expect-dev),可以欺骗程序认为它连接到TTY。

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

#1


26  

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.

unbuffer,期待的一部分(Ubuntu Lucid上的sudo apt-get install expect-dev),可以欺骗程序认为它连接到TTY。

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