无法写入pty-Linux [英] cannot write to pty - linux
问题描述
我是这样创建的pty设备的所有者权限是crw-w ----
mknod pty1 c 1 1猫>pty1
告诉我不允许进行操作.
稍后我要做的是,我使用open打开一个程序中的文件,然后调用write将输出发送到终端,就好像它是一个磁盘文件一样.
为什么猫不工作.我们可以写一个pty 还是从pty读,使用打开和写入.
我们可以从Java中做到这一点吗?java写入实际上是pty的文件.
问题的来源:强制程序在重定向时刷新其标准输出更新:这个问题不清楚.我需要添加更多信息吗?
ls -la
的输出 crw--w ---- 1个iamrohitbanga用户1,1 2010-01-13 18:27 pty1crw--w ---- 1 iamrohitbanga用户1,2 2010-01-13 18:29 pty2
也
我什么时候做在一个终端中为cat/dev/pts/0,在另一个终端中为cat>/dev/pts/0,我看不到一个终端的输入被转移到另一终端.
那不是PTY的工作方式;您应该阅读 man 4 pty
和 man 4点
.(不再使用旧的BSD风格的设备.)
为了打开伪终端从站(PTS), posix_openpt(3)
),并使用 grantpt(3)
和 unlockpt(3)
.
使用 forkpty(3)
等.辅助函数比自己调用低级函数要容易得多.
即使在那之后,它也不像FIFO(您似乎期望的那样)那样工作:写入PTS的任何内容都会在PTM上出现,而从PTS读取的任何内容都是从PTM写入的.
i am the owner of the pty device created like this permissions are crw-w----
mknod pty1 c 1 1
cat > pty1
tells me operation not permitted.
what i want to do later is that i open the file from a program using open and call write to send output to the terminal, as if it is a disk file.
why is cat not working. can we write to a pty or read from a pty using open and write.
can we do this from java. java writes to a file that is actually a pty.
source of problem: forcing a program to flush its standard output when redirected
Update: is the question not clear. do i need to add more info?
output of ls -la
crw--w---- 1 iamrohitbanga users 1, 1 2010-01-13 18:27 pty1
crw--w---- 1 iamrohitbanga users 1, 2 2010-01-13 18:29 pty2
also
when i do cat /dev/pts/0 in one terminal and cat > /dev/pts/0 in another, i do not see the input of one getting transferred to another.
That's not how PTYs work; you should read man 4 pty
and man 4 pts
. (The old BSD-style devices should no longer be used.)
In order to open a pseudo-terminal slave (PTS, the /dev/pts/#
returned by ptsname(3)
), another program must create a pseudo-terminal master (PTM, returned by posix_openpt(3)
) and enable the PTS with grantpt(3)
and unlockpt(3)
.
Using the forkpty(3)
etc. helper functions is a lot easier than calling the low-level functions yourself.
And even after that, it doesn't work like a FIFO (which you seem to be expecting): anything written into the PTS comes out on the PTM, and anything read from the PTS is written from the PTM.
这篇关于无法写入pty-Linux的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!