如何解决pty主端输出奇怪
我正在开发一个远程Shell程序,我用forkpty()
创建了一个pty。从跟随者端到领导者端的写作按预期工作,但是当我开始尝试在跟随者端进行阅读时,我在领导者端得到了奇怪的输出。
我明白了:
$
socket->pty: interesting
pty->socket: ^@^@^@^@^@^@^@^@^@^@▒▒ɖ^BE<^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^X▒߰^@^@^@^@^@^@^@^@^@^@^@^@^@^@ ^@^@^@^@^@^@^@^@^@^@^@^@^C^@^@▒^E^@^@▒ ^@^@▒ ^@^@▒ ^@^@▒ ^@^@▒ ^@^@▒ ^@^@▒ ^@^@▒^@^@▒ ^@^@▒ ^@^@▒ ^@^@▒ ^@^@▒ ^@^@▒ ^@^@▒ ^@^@▒ ^@^@▒ ^@^@▒ ^@^@▒ ^@^@▒ ^@^@▒ ^@^@▒ ^@^@▒^@^@▒ ^@^@^@^@^@^@^@^@^@^@^@^A^@^@@^@^@^@^@^@^@^@@^@^@^@^@^B^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@@^@@^@^@^@^@^@^K^@^@^@^@^@^@^@▒▒▒^@^@^@^@^@▒^@^@^@^@^@^@^@▒▒^@^@=L@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@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@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@@^@@^@^@^@^@^@^K^@^@^@^@^@^@^@▒▒▒^@^@^@^@^@▒^@^@^@^@^@^@^@▒▒C▒^@^@▒L@^@^@^@^@^@^@^@^@
socket->pty: what
pty->socket: s^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^A▒x▒^@^@@`P▒^@^@^A▒▒▒▒▒▒▒^H▒x▒^@^@▒▒x▒^@^@^@^@^@^@^@^@^@^@▒ ^_▒^AM<^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^X"W▒^@^@^@^@^@^@^@^@^@^@^@^@^@^@ ^@^@^@^@^@^@^@^C^@^@▒^E^@^@▒ ^@^@▒ ^@^@▒ ^@^@▒ ^@^@▒ ^@^@▒ ^@^@▒ ^@^@▒ ^@^@▒ ^@^@▒ ^@^@▒ ^@^@▒^@^@▒ ^@^@▒ ^@^@▒ ^@^@▒ ^@^@▒ ^@^@▒ ^@^@▒ ^@^@▒ ^@^@▒ ^@^@▒ ^@^@▒ ^@^@▒ ^@^@^@^@^@^@^@^@^@^@^@^A^@^@@^@^@^@^@^@^@^@@^@^@^@^@^B^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@@^@@^@^@^@^@^@^K^@^@^@^@^@^@^@▒▒▒^@^@^@^@^@▒^@^@^@^@^@^@^@▒▒C▒^@^@▒L@^@^@^@^@^@^@^@^@
它似乎在重复,但我不知道它是什么。
跟随者的代码
fprintf(stdout,"$");
fgets(input_buff,buff_len,stdin);
领导者代码
chars_read = read(leader_fd,&buff,buff_len - 1);
if (chars_read > 0) {
buff[chars_read] = '\0';
printf("pty->socket: %s\n",buff);
write(socketfd,buff,chars_read);
}
chars_read = read(socketfd,buff_len - 1);
if (chars_read > 0) {
buff[chars_read] = '\0';
printf("socket->pty: %s\n" buff);
write(leader_fd,chars_read);
}
当我从关注者端删除fgets
时,我的输出将变为:
socket->pty: what
pty->socket: .txt: No such file or directory
$56152 (started): cat hello.txt
cat: hello.txt: No such file or directory
$56153 (started): cat hello.txt
cat: hello.txt: No such file or directory
$56154 (started): cat hello.txt
cat: hello.txt: No such file or directory
$56155 (started): cat hello.txt
cat: hello.txt: No such file or directory
$56156 (started): cat hello.txt
cat: hello.txt: No such file or directory
$56157 (started): cat hello.txt
cat: hello.txt: No such file or directory
$56158 (st
socket->pty: why?
pty->socket: arted): cat hello.txt
cat: hello.txt: No such file or directory
$56159 (started): cat hello.txt
cat: hello.txt: No such file or directory
$56160 (started): cat hello.txt
cat: hello.txt: No such file or directory
$56161 (started): cat hello.txt
cat: hello.txt: No such file or directory
$56162 (started): cat hello.txt
cat: hello.txt: No such file or directory
$56163 (started): cat hello.txt
cat: hello.txt: No such file or directory
$56164 (started): cat hello.txt
为什么在追随者方面的阅读会导致在领导者方面的阅读混乱?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。