简体   繁体   English

我怎样才能回复/ dev / tty?

[英]How can I echo to /dev/tty?

Is there a way to send something like an "end of data" after executing 有没有办法在执行后发送类似“数据结束”的内容

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

$ 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

You cannot do it like that. 你不能这样做。 The '>' redirection operator makes it so that for the WHOLE execution time standard input IS the echo command, and you can't just change it later. '>'重定向操作符使得对于WHOLE执行时标准输入IS是echo命令,您不能稍后更改它。

You might want to rethink your needs and implementation. 您可能想重新考虑您的需求和实施。

Using echo > /dev/tty you can't achieve that. 使用echo > /dev/tty你无法做到这一点。 But you can do that by sending a signal to process which are using that tty. 但是你可以通过向正在使用该tty的进程发送信号来做到这一点。

For example: 例如:

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

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 ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM