Difference between <stdin> & terminal


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Difference between <stdin> & terminal
# 1  
Old 06-29-2007
Difference between <stdin> & terminal

Hi,

What's the difference in taking inputs from <stdin> and terminal.
When by default <stdin> points to terminal itself.

Thanks
# 2  
Old 06-29-2007
By convention every process has three standard file descriptors open when it is started by a shell.

0 - stdin
1 - stdout
2 - stderr

and when you log on from a console, serial terminal or use xterm or ssh then all of these normally are open on /dev/tty which maps to your "controlling terminal".

Notice that when you type three main things happen:

1. you can press delete and do basic editing
2. nothing happens until you press return
3. you can do flow/control with ctrl-S and ctrl-Q.

This is referred to as 'cooked' mode, and all terminals can operate either cooked or raw.

Files or pipes on the other hand can only be raw unless special effort is made to pipe through a pseudo-terminal.

Being able to replace stdin with reading from a file or the output of another program is very powerful, but sometimes a program needs to know if it is reading from a terminal or not, this is also often counted as "interactive" or not. A program can do this with "istty".
# 3  
Old 06-29-2007
Couldn't understand the whole thing.

But some commands read from <stdin> and some from terminal.

What's this and do i differentiate in this.
# 4  
Old 06-29-2007
well,
terminal generally means from the keyboard
<stdin> can be from a piped in file or terminal etc.
# 5  
Old 06-29-2007
<stdin> by default, points to the terminal/keyboard.
But it is not always true if you redirect or use pipes.
In other words, there are three ways that <stdin> can be used:
1) Terminal/keyboard, by default: cut -c2<enter>
2) Redirection of a file: cut -c2 input_file OR cut -c2 < input_file
3) Use of pipes: echo "abc123" | cut -c2
# 6  
Old 06-29-2007
Quote:
Originally Posted by vibhor_agarwali
But some commands read from <stdin> and some from terminal.
Ah, some programs explicitly open /dev/tty in order to read from the terminal and do not want piped input. A good example is a program (eg ssh) that needs to read a password, it wants it typed in by a person.
# 7  
Old 06-30-2007
Quote:
Originally Posted by porter
Ah, some programs explicitly open /dev/tty in order to read from the terminal and do not want piped input. A good example is a program (eg ssh) that needs to read a password, it wants it typed in by a person.
That's a good example.

But not always, in the case of password-less ssh through the use of keys in .ssh directory.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Difference between & and nohup &

Hi All, Can anyone please help me understanding what the difference between the below two? 1. script.sh & 2. nohup script.sh & (2 Replies)
Discussion started by: Anupam_Halder
2 Replies

2. UNIX for Dummies Questions & Answers

Difference between console and Terminal.

I see these terms used all the time with hardly any distinction between the two. Any clarification would be appreciated!:) I could only get emacs to open in console so I was also wondering what are the common applications to use in console.:wall: (7 Replies)
Discussion started by: theKbStockpiler
7 Replies

3. Shell Programming and Scripting

STDERR to file & terminal using tee

Hi All, Solarix/Bash v3x Im trying to output any standard errors created by the script to a file using the below command: . runDTE.sh 2> "$DTE_ERROR_FILE" however the errors do get written to the dir/file stored in $DTE_ERROR_FILE but the error does not appear on the terminal screen in... (4 Replies)
Discussion started by: satnamx
4 Replies

4. Solaris

Difference between sudo & RBAC

Hello Everybody I would like to know any major difference between sudo & RBAC as I am bit familiar with RBAC but not with sudo (2 Replies)
Discussion started by: girish.batra
2 Replies

5. UNIX for Advanced & Expert Users

Pseudo-terminal will not be allocated because stdin is not a terminal.

I am trying to automate a SSH login using Keys using the following command ssh -i id_rsa usernamw@ipaddr. I am successful in doing this and i am getting the Warning Screen and I logon successfully. but when I am executing the command tail -1cf put.dat | ssh -i id_rsa username@ipaddr > get.dat ... (1 Reply)
Discussion started by: Shivdatta
1 Replies

6. Programming

C++ How to use pipe() & fork() with stdin and stdout to another program

Hi, Program A: uses pipe() I am able to read the stdout of PROGAM B (stdout got through system() command) into PROGRAM A using: * child -> dup2(fd, STDOUT_FILENO); -> execl("/path/PROGRAM B", "PROGRAM B", NULL); * parent -> char line; -> read(fd, line, 100); Question:... (2 Replies)
Discussion started by: vvaidyan
2 Replies

7. UNIX for Dummies Questions & Answers

Difference between && and -a

I've come stuck when I was making sure the hour of the day was not been two times so that the rest of the script could not be executed. Seems simple enough. I used the -a to join the two conditions together and it would run if the conditions was t/f ( it is only supposed to run if was t/t).... (3 Replies)
Discussion started by: spookyrtd99
3 Replies

8. Shell Programming and Scripting

Difference between ./ & . ./ ???

For executing a shell script, i know 2 ways: 1) using sh command 2) making the script file executable & then use ./ But i can across another way for executing the scripts... using ". ./" I tried this way.. but i was able to understand the difference between "./" and ". ./" I would be very... (2 Replies)
Discussion started by: abishekmag
2 Replies

9. UNIX for Advanced & Expert Users

What is the difference between Unix & linux

:confused: Hi All Can anyone help me in finding the answer of the question mentioned below. What is the difference between Unix & linux ? Thanks in Advance to all CSaha (1 Reply)
Discussion started by: csaha
1 Replies

10. UNIX Desktop Questions & Answers

what is the difference between Unix & linux, what are the advantages & disadvantages

ehe may i know what are the difference between Unix & Linux, and what are the advantages of having Unix as well as disadvantages of having Unix or if u dun mind i am dumb do pls tell me what are the advantages as well as the disadvantages of having linux as well. thanks (1 Reply)
Discussion started by: cybertechmkteo
1 Replies
Login or Register to Ask a Question