The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Pseudo-terminal will not be allocated because stdin is not a terminal. Shivdatta UNIX for Advanced & Expert Users 1 08-04-2008 11:29 AM
How to write to stdin of another program (program A -> [stdin]program B) vvaidyan UNIX for Dummies Questions & Answers 3 08-02-2008 06:21 PM
How to write to stdin of another program (program A -> [stdin]program B) vvaidyan High Level Programming 1 04-30-2008 02:44 PM
what difference between "terminal" and "console" chenhao_no1 High Level Programming 1 09-09-2002 10:46 AM
connecting to unix through hyper terminal - as a dumb terminal michelle UNIX for Advanced & Expert Users 2 11-05-2001 03:32 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-29-2007
vibhor_agarwali vibhor_agarwali is offline
Registered User
  
 

Join Date: Jan 2005
Posts: 259
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 (permalink)  
Old 06-29-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
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 (permalink)  
Old 06-29-2007
vibhor_agarwali vibhor_agarwali is offline
Registered User
  
 

Join Date: Jan 2005
Posts: 259
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 (permalink)  
Old 06-29-2007
bigearsbilly bigearsbilly is offline
Registered User
  
 

Join Date: Feb 2006
Location: Southern England
Posts: 104
well,
terminal generally means from the keyboard
<stdin> can be from a piped in file or terminal etc.
  #5 (permalink)  
Old 06-29-2007
Shell_Life's Avatar
Shell_Life Shell_Life is offline
Registered User
  
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
<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 (permalink)  
Old 06-29-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
Quote:
Originally Posted by vibhor_agarwali View Post
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 (permalink)  
Old 06-30-2007
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,958
Quote:
Originally Posted by porter View Post
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.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:51 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0