Re: Detect if stdin is via keyboard or via < file?



srbstar@xxxxxxxxxxxxx wrote:

> Can a program detect if it's stdin is
> coming from keyboard input vs. being
> redirected from a file?
>
> If it's from a file, I want to fputs()
> the text. But if it's from the keyboard,
> I won't (don't want it typed, then
> fputs()'d.

I found the most straightforward tactic in a similar situation
(whether to issue a prompt or not, for an interactive interpreter)
to be a command-line flag. The program no longer needs to be able
to answer the question.

--
Chris "electric hedgehog" Dollin
Almost all predictions about life in 2015 are wrong in some fundamental
respect.
.



Relevant Pages

  • Re: Detect if stdin is via keyboard or via < file?
    ... > coming from keyboard input vs. being ... Not in standard C, it can't. ... But, with a platform-specific extension, it often can. ... or use a platform-specific extension to determine whether stdin ...
    (comp.lang.c)
  • Re: Detect if stdin is via keyboard or via < file?
    ... Lew Pitcher wrote: ... >> Can a program detect if it's stdin is coming from keyboard input ... > But, with a platform-specific extension, it often can. ... > determine whether stdin comes from a file or an interactive device. ...
    (comp.lang.c)
  • Read from keyboard with redirected stdin
    ... I'm writing a program which acts as a filter, so stdin and stdout will be ... file can I read from to get keyboard input in any case? ...
    (freebsd-questions)
  • Re: pipe in cmd-line text but then reset STDIN for menu
    ... (i.e. less reads its input from stdin, but can also read the terminal). ... to find out will be to read the source code of 'less'. ... if (tty < 0) ... it opens /dev/tty for keyboard input, and falls back to fd 2 if ...
    (comp.lang.ruby)
  • Re: receiving input from different sources
    ... Keyboard input comes on STDIN, and you can not use STDIN for something ... STDIN as another file descriptor, and then the new process will reopen ...
    (perl.beginners)