Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!bcm!shell!shell!rjohnson From: rjohnson@shell.com (Roy Johnson) Newsgroups: comp.lang.c Subject: Re: stdin and UNIX pipes Message-ID: Date: 19 Feb 91 23:12:51 GMT References: <92993@unix.cis.pitt.edu> Sender: usenet@shell.shell.com (USENET News System) Distribution: na Organization: Shell Development Company, Bellaire Research Center, Houston, TX Lines: 37 In-Reply-To: nr3m@unix.cis.pitt.edu's message of 18 Feb 91 03:11:51 GMT In article <92993@unix.cis.pitt.edu> nr3m@unix.cis.pitt.edu (Matthew A Henry) writes: >I am writing a C program in a UNIX environment that will receive input >from other programs through a pipe, causing the shell to change the >default assignment of stdin. At some point in the program I would like >to request input from the original stdin (keyboard). Any thoughts on >how I could do this, e-mailed or posted, would be greatly appreciated. The file "/dev/tty" should be your keyboard for input (it is on my Sun). I think you want something like this: #include main() { int i; if (freopen("newfile", "r", stdin) != stdin) { perror("freopen"); exit(1); } /* Get 50 chars from "newfile" */ for(i=0; i<50; ++i) putchar(getchar()); /* Change back to stdin */ if (freopen("/dev/tty", "r", stdin) != stdin) { perror("freopen"); exit(1); } /* Get 50 chars from keyboard */ for(i=0; i<50; ++i) putchar(getchar()); } -- ======= !{sun,psuvax1,bcm,rice,decwrl,cs.utexas.edu}!shell!rjohnson ======= Feel free to correct me, but don't preface your correction with "BZZT!" Roy Johnson, Shell Development Company