Xref: utzoo comp.lang.c:29176 comp.unix.xenix:11781 Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!texbell!vector!void!ozdaltx!root From: root@ozdaltx.UUCP (root) Newsgroups: comp.lang.c,comp.unix.xenix Subject: help w/pipe read Message-ID: <6322@ozdaltx.UUCP> Date: 29 May 90 01:21:17 GMT Expires: 3 Jun 90 23:02:00 GMT Followup-To: root@ozdaltx Distribution: usa Organization: AIDS INFO EXCG/OZ BBS - Dallas, TX Lines: 66 Situation: Read characters from a pipe (one at a time) and at the same time scan the keyboard for a command without disrupting the pipe input. Conditions: Stdin and stdout have been closed, ttfp has been opened for reading and writing (fopen w/r+). CBREAK (only) is in effect. What happens: The pipe is read successfully, but the program waits until some key is struck on the keyboard before it prints anything else from the pipe. I have tried fgetc, fscanf and just about everything else I can think of.... What am I missing (see below)? Thanks in advance... Scotty ----- AIDS INFORMATION EXCHANGE BBS (214) 247-2367/247-5609 "Education is the best weapon" {mic,void,egsner}!ozdaltx!sysop || {uunet,smu,ames}!sulaco!ozdaltx!sysop ---------------------------------------------------------------------- int pread() { /* reads the pipe and displays one char at a time ** while checking the keyboard for input */ FILE *fd; /* fd is the PIPE pointer created earlier */ int q; int rc; char rcmd[1][3]; int c; rcmd[0][0]='\0'; q = 0; if((fd = fopen(PIPE, "r+")) == 0){ return(0); } setbuf(fd, 0); while(1) { rc = getc(fd); putc(rc,ttfp); /* put a char from the pipe to the tty*/ q=0; if(isspace(rc)){ fflush(fd); fread(rcmd,1,1,ttfp); /* ttfp is opened [r+] in main() as the tty */ fflush(ttfp); c='\0'; c = (int)rcmd[0][0]; if(c == ':'){ fprintf(ttfp,"\nCommand: "); c=getc(ttfp); switch(c){ case 'Q': case 'q': fclose(fd); return(0); } } c='\0'; } } fclose(fd); return(0); }