[cs631apue] Suspend stdin, wait for another user input

Tejas Nadkarni tnadkarn at stevens.edu
Sat Dec 7 08:44:25 EST 2013


FYI...I tried using this and didn't get it to work but there is a way to do
this using freopen, dup, dup2 by saving stdin,stdout then redirecting to
dev/tty and then restoring them back. This method seems to work the best
for me. Thanks.



On Thu, Nov 28, 2013 at 5:02 AM, kwang9 <kwang9 at stevens.edu> wrote:

> 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
>>
> _______________________________________________
> cs631apue mailing list
> cs631apue at lists.stevens.edu
> https://lists.stevens.edu/mailman/listinfo/cs631apue
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.stevens.edu/pipermail/cs631apue/attachments/20131207/4cd4058d/attachment.html>


More information about the cs631apue mailing list