怎么会有时错误,有时正确?
hbcb 2005-07-14 08:33:12 Red Hat Linux 9
test.c
#include <stdio.h>
/*简化了的代码*/
int main(){
char str[256];
FILE *fp;
/*显示环境变量TTY,若无则用tty命令取得*/
if((fp=popen("echo $TTY;tty","r"))!=NULL){
while(fgets(str,256,fp)){
printf("%s",str);
break; /*前面会经过其他处理,当条件达到就退出。*/
};
pclose(fp);
};
return(0);
}
运行时有时提示“tty: 写入时发生错误: 断开的管道”,有时又没有这样的错误提示
请问是什么原因造成这样不稳定呢?要怎么解决?