Linux 我怎样才能回显到 /dev/tty?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16080186/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 22:44:35  来源:igfitidea点击:

How can I echo to /dev/tty?

linuxshellcygwinttyterm

提问by inselberg

Is there a way to send something like an "end of data" after executing

有没有办法在执行后发送类似“数据结束”的内容

echo "test" > /dev/tty1

echo "test" > /dev/tty1

in order to gain the "input cursor" back to "receiving" terminal (in this case tty1)?

为了将“输入光标”返回到“接收”终端(在本例中为 tty1)?

Screenshot: http://picload.org/image/acdwigg/tty.png

截图:http: //picload.org/image/acdwigg/tty.png

采纳答案by Reishin

Using echo > /dev/ttyyou can't achieve that. But you can do that by sending a signal to process which are using that tty.

使用echo > /dev/tty你无法实现。但是您可以通过向正在使用该 tty 的进程发送信号来做到这一点。

For example:

例如:

kill -s SIGINT `ps -ft pts/2 | grep pts/2 | cut -d ' ' -f 5`

回答by Steven Penny

$ echo "test" > /dev/tty
test
Cygwin supports the following character devices commonly found on POSIX systems:

/dev/tty    The current controlling tty of a session.

Special filenames

Special filenames

回答by blue

You cannot do it like that. The '>' redirection operator makes it so that for the WHOLE execution time standard input IS the echocommand, and you can't just change it later.

你不能那样做。'>' 重定向运算符使得整个执行时间的标准输入是echo命令,您不能稍后更改它。

You might want to rethink your needs and implementation.

您可能需要重新考虑您的需求和实施。

回答by LinconFive

centos will print out your string in the console you select

centos 将在您选择的控制台中打印出您的字符串

#run on pts/8
[root@C203-ATC ONT]# uname -a
Linux C203-ATC 2.6.32-504.el6.x86_64 #1 SMP Wed Oct 15 04:27:16 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
[root@C203-ATC ONT]# echo "test" > /dev/pts/3
[root@C203-ATC ONT]# 

[root@C203-ATC BASIC]# tty
/dev/pts/3
#checked on pts/3  
[root@C203-ATC BASIC]# test
(cursor)
#cursor pending ...