重定向标准输入来自使用bash不同的终端 [英] redirect the stdin to come from a different terminal using Bash

查看:194
本文介绍了重定向标准输入来自使用bash不同的终端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道人们会如何去从当前的xterm会议即/ dev的重定向脚本的标准输入/ PTS / 0一还运行即的/ dev /使用bash PTS / 1?我有一个打开的xterm 3窗户bash脚本,我想从只有一个窗口输入,我无法弄清楚如何做到这一点。任何帮助AP preciated!谢谢。

I'm wondering how one would go about redirecting the stdin of a script from the current xterm session i.e. /dev/pts/0 to one that is also running i.e /dev/pts/1 using bash? I have a bash script that opens 3 xterm windows and I want to get input from only one of those windows and I cannot figure out how to do it. Any help is appreciated! thanks.





修改(从下面移动 - OP提交了该澄清的答案)



EDIT (Moved from below -- OP submitted this clarification as an answer)

我想我应该澄清了我想做的事。我将从PTY启动脚本,让我们说这是为/ dev / PTS / 3。该脚本将打开3 XTerminals使用,可以说是:/ dev / PTS / 0中,/ dev / PTS / 1,和/ dev / PTS / 2。这3个新的pty是什么用户会看到的。该脚本会询问一些用户输入,我想用户的输入被输入到的/ dev / PTY / 1和程序应该得到它的信息来自那里。不过,我一直在努力,做到这一点,这是行不通的。这里是我的code片段。

I guess I should have clarified what I wanted to do. I will start a script from a pty, let's say it's /dev/pts/3. This script will open 3 xterminals, lets say: /dev/pts/0, /dev/pts/1, and /dev/pts/2. These 3 new ptys are what the user is going to see. The script asks the user for some input and I want the input of the user to be typed into /dev/pty/1 and the program should get it's info from there. However I've tried to do this and it doesn't work. Here's a snippet of my code.

exec</dev/pts/1

echo
echo "Would you like to search for more info?" 1>/dev/pts/1
read answer

case $answer in
    y) echo "YES" ;;
    n) echo "NO"  ;;
    *) echo "y/n only!";;
esac

在最后的case语句是只是一个小的占位符,看看输入的实际工作。

The case statement at the end is just a little placeholder to see if the input actually worked.

推荐答案

我怀疑这是不可能的。据我所知,没有在内核空间修改的东西,这是不可能读取一个TTY(或控股)输入的不是当前的tty。甚至根本不能做到这一点。我花了一些时间寻找到这一点,我无法找出如何做到这一点,但我没有找到很多自称来源这是不可能的。这似乎是一个设计决策,以提高用户的安全/隐私。

I suspect this is not possible. AFAIK, without modifying something in kernel space, it's impossible to read the input from a tty (or pty) that is not the current tty. Even root can't do it. I spent some time looking into this and I was unable to find out how to do it, but I did find lots of sources claiming it was impossible. This appears to have been a design decision to increase security/privacy of users.

这篇关于重定向标准输入来自使用bash不同的终端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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