当前位置: 技术问答>linux和unix
怎样写标准输入,这个管道有什么错?
来源: 互联网 发布时间:2015-03-12
本文导语: int main(int argc, char *argv[]) { int cid=0; char buf[1024],usr[]="test"; int to[2],from[2]; pipe(to); pipe(from); cid=fork(); if(cid>0) { close(to[0]); close(from[1]); close(0); dup(from[0]); close(from[0]); close(1); dup(to[1]); close(to[1]); system...
int main(int argc, char *argv[])
{
int cid=0;
char buf[1024],usr[]="test";
int to[2],from[2];
pipe(to);
pipe(from);
cid=fork();
if(cid>0)
{
close(to[0]);
close(from[1]);
close(0);
dup(from[0]);
close(from[0]);
close(1);
dup(to[1]);
close(to[1]);
system("su");
}
close(to[1]);
close(0);
dup(to[0]);
close(to[0]);
close(from[0]);
close(1);
dup(from[1]);
close(from[1]);
while(fgets(buf,1024,stdin))
{
printf("rn%srn",buf);
if(strstr(buf,"Password:")!=NULL)
fwrite(usr,4,1,stdout);
}
}
错误提示:
standard in must be a tty
{
int cid=0;
char buf[1024],usr[]="test";
int to[2],from[2];
pipe(to);
pipe(from);
cid=fork();
if(cid>0)
{
close(to[0]);
close(from[1]);
close(0);
dup(from[0]);
close(from[0]);
close(1);
dup(to[1]);
close(to[1]);
system("su");
}
close(to[1]);
close(0);
dup(to[0]);
close(to[0]);
close(from[0]);
close(1);
dup(from[1]);
close(from[1]);
while(fgets(buf,1024,stdin))
{
printf("rn%srn",buf);
if(strstr(buf,"Password:")!=NULL)
fwrite(usr,4,1,stdout);
}
}
错误提示:
standard in must be a tty
|
我在HP机器上可以编译通过,运行也没有问题。(我是用Telnet登录上去的)
你将标准输入输出都close了,又想从stdin读东西,是不是因为这个?
你将标准输入输出都close了,又想从stdin读东西,是不是因为这个?