Distingushing between console & redirected input

Distingushing between console & redirected input

Post by nowa » Thu, 30 Dec 1999 04:00:00



I am writing a small utility that accepts input from stdin. I need it
to behave differently if the input is being typed in or if it's
redirected from a file.

I knew how to do this once but unfortunatly, iv'e been developing
primarily for Windows for the last few years.

 
 
 

Distingushing between console & redirected input

Post by Lew Pitch » Thu, 30 Dec 1999 04:00:00



>I am writing a small utility that accepts input from stdin. I need it
>to behave differently if the input is being typed in or if it's
>redirected from a file.

>I knew how to do this once but unfortunatly, iv'e been developing
>primarily for Windows for the last few years.

man isatty

Lew Pitcher
System Consultant
Toronto Dominion Financial Group


(Opinions expressed are my own, not my employer's.)

 
 
 

Distingushing between console & redirected input

Post by Colin Walter » Thu, 30 Dec 1999 04:00:00



> I am writing a small utility that accepts input from stdin. I need
> it to behave differently if the input is being typed in or if it's
> redirected from a file.

I believe the function you are looking for is isatty()

--

http://web.verbum.org/levanti
(1024D/C207843A) A580 5AA1 0887 2032 7EFB  19F4 9776 6282 C207 843A

 
 
 

Distingushing between console & redirected input

Post by nowa » Thu, 30 Dec 1999 04:00:00


Thanx :)




> >I am writing a small utility that accepts input from stdin. I need it
> >to behave differently if the input is being typed in or if it's
> >redirected from a file.

> >I knew how to do this once but unfortunatly, iv'e been developing
> >primarily for Windows for the last few years.

> man isatty

> Lew Pitcher
> System Consultant
> Toronto Dominion Financial Group


> (Opinions expressed are my own, not my employer's.)

 
 
 

Distingushing between console & redirected input

Post by Marcus Thiesse » Fri, 31 Dec 1999 04:00:00



> I am writing a small utility that accepts input from stdin. I need it
> to behave differently if the input is being typed in or if it's
> redirected from a file.

tty(1)/pty(1) should give you some information whether stdin is a
terminal or pseudo-terminal or it is not (e.g. a file).

If prefer C/C++ you may wish the check out the man pages on
[fl]stat. The st_mode field in struct stat can help you to determine
the file type (regular vs character/blk special).

HTH,

--Marcus

 
 
 

1. Redirecting user input from the console

I am trying to redirect user input from the console and just can't
seem to get it right. std output and std error are no problem but I
can't get std input to do just what I need.

All I am doing is running a tar backup from crontab. The backup takes
two tapes. So I want the message to insert the next tape to go to the
console (this works fine) and then when the tape has been changed the
response (pressing the return key) should be from the console (this
does not seem to work).

Obviously I am not a shell script expert. So a little guidance in the
right direction would be great.

Thanks

2. 8-Port-Adapter problems under 3003

3. Redirect Console Input

4. Volume manager, what am I doing wrong now?

5. Redirecting input to a file - echo the input to screen/file?

6. Kernel Panic --- System wont boot!

7. How to redirect input/output to local&remote display

8. lost login when using telnet

9. Merging keyboard input with serial console input?

10. X-Windows not redirecting console output to console window

11. How to read redirected input?

12. Redirecting input

13. Redirecting input and output to serial port