[cs631apue] Suspend stdin, wait for another user input

kwang9 kwang9 at stevens.edu
Thu Nov 28 05:02:40 EST 2013


Dear Shen,

while (read(...)) ;                   // read all content from stdin, it 
fails when file is BIG
freopen("/dev/tty", "r", stdin);      // redirect stdin back to terminal
printf("Input phrase:\n");            // prompting
read(...);

Anyway there's another work around:

FILE *phr_fd=fopen("/dev/tty", "r");  // get terminal's fd first
printf("Input phrase:\n");            // prompting
read(...);
fclose(phr_fd);
while (read(...)) {                   // do work now
     /* deal line by line */
}

在 2013-11-28 03:39,Hongyi Shen 写道:
> This problem has frustrated me for hours.
> 
> In the requirement of HW5,
> 
> echo "Kookaburra has left the tree" | aed -e | aed -d
> 
> Then we want user to input passphrase, but scanf will
> read "Kookaburra has left the tree" first, instead of waiting for
> user's passphrase.
> 
> (When use pipe, isatty might be a way)
> 
> Thank you all, enjoy the holiday.
> 
> _______________________________________________
> cs631apue mailing list
> cs631apue at lists.stevens.edu
> https://lists.stevens.edu/mailman/listinfo/cs631apue


More information about the cs631apue mailing list