mandavi
mandavi

Reputation: 485

trying to understand stdin, stdout

I am trying to understand stdin, stdout...and these are few questions i have
here's the code i am using:

int main()  
{  
    struct termios new;  
    tcgetattr(1,&new);  
    new.c_lflag &= ~ECHO;  
    tcsetattr(1,TCSAFLUSH,&new);  
    return 0;  
}  

I want to know what happens if i turn ECHO off on stdin rather than stdout....i mean, in both the cases i experience same result....how do they differ??

And what does stty command returns??
After running the above program, i did stty and found -echo for line=0, if i am right, it is ECHO off on stdin, but the program turns the ECHO flag off for stdout??
Sorry, if my doubts sound noob :(

Upvotes: 1

Views: 401

Answers (1)

Šimon Tóth
Šimon Tóth

Reputation: 36423

This is terminal control. And if both your stdin and stdout are connected to the same terminal, then you are still managing the same objects configuration.

tcgetattr simply gets information about the object associated with the filedescriptor.

Of course they don't have to be associated with the same terminal. For example if you run:

./a.out >file.out then stdin will still be attached to the terminal, but stdout is now attached to a file.

Upvotes: 2

Related Questions