Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #57385

Re: Reading From stdin After Command Line Redirection

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.055
X-Spam-Evidence '*H*': 0.89; '*S*': 0.00; 'expected.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'runs': 0.10; "wouldn't": 0.14; 'finney': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:Line': 0.16; 'subject:Reading': 0.16; 'tty': 0.16; 'input': 0.22; 'header:User- Agent:1': 0.23; '(by': 0.24; 'instead.': 0.24; 'file.': 0.24; 'this:': 0.26; 'header:X-Complaints-To:1': 0.27; 'tim': 0.29; 'writes:': 0.31; 'file': 0.32; 'run': 0.32; 'usual': 0.35; 'there': 0.35; 'so,': 0.37; 'ben': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'read': 0.60; 'entire': 0.61; 'first': 0.61; "you've": 0.63; 'skip:n 10': 0.64; 'more': 0.64; 'different': 0.65; 'skip:\xe2 10': 0.65; '8bit%:21': 0.69; 'odds': 0.84; 'religion': 0.84; 'subject:After': 0.84; 'why?': 0.91; 'subject:From': 0.97
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Ben Finney <ben+python@benfinney.id.au>
Subject Re: Reading From stdin After Command Line Redirection
Date Thu, 24 Oct 2013 07:46:43 +1100
References <7cdlja-j3j2.ln1@ozzie.tundraware.com>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 8bit
X-Gmane-NNTP-Posting-Host rasputin.madmonks.org
X-Public-Key-ID 0xAC128405
X-Public-Key-Fingerprint 517C F14B B2F3 98B0 CB35 4855 B8B2 4C06 AC12 8405
X-Public-Key-URL http://www.benfinney.id.au/contact/bfinney-gpg.asc
X-Post-From Ben Finney <bignose+hates-spam@benfinney.id.au>
User-Agent Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux)
Cancel-Lock sha1:CDU+D9gJb68kj8j2ptCTPPJyh/Y=
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1427.1382561215.18130.python-list@python.org> (permalink)
Lines 34
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1382561215 news.xs4all.nl 15947 [2001:888:2000:d::a6]:57301
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:57385

Show key headers only | View raw


Tim Daneliuk <tundra@tundraware.com> writes:

> I have a program that runs like this:
>
>   foo.py <inputfile

That's one way to run it. If the user chooses to run it that way, they
have chosen deliberately to run the program non-interactively.

> I want to reconnect stdin to the tty as usual after 'inputfile'
> has been read so that things like raw_input and getpass
> will work as expected.

Why? That's at odds with how the user has already chosen to run the
program. If they wanted to run the program interactively, they wouldn't
have chosen to redirect standard input.

> So, after I do .... = sys.stdin.readlines(), how to I reopen
> stdin in its nonredirected mode?

There would be no point; standard input was never attached to the
console in the first place, it was attached (by the person who chose the
above invocation) to a different file instead. You've already read the
entire file.

Can you speak more about how you intend your program to be used? The
above request is incoherent, and I suspect you've made a design mistake.

-- 
 \       “Philosophy is questions that may never be answered. Religion |
  `\              is answers that may never be questioned.” —anonymous |
_o__)                                                                  |
Ben Finney

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Reading From stdin After Command Line Redirection Tim Daneliuk <tundra@tundraware.com> - 2013-10-23 12:25 -0500
  Re: Reading From stdin After Command Line Redirection Chris Angelico <rosuav@gmail.com> - 2013-10-24 07:40 +1100
  Re: Reading From stdin After Command Line Redirection Ben Finney <ben+python@benfinney.id.au> - 2013-10-24 07:46 +1100
  Re: Reading From stdin After Command Line Redirection Chris Angelico <rosuav@gmail.com> - 2013-10-24 07:52 +1100
  Re: Reading From stdin After Command Line Redirection random832@fastmail.us - 2013-10-23 17:01 -0400
  Re: Reading From stdin After Command Line Redirection Ben Finney <ben+python@benfinney.id.au> - 2013-10-24 09:20 +1100
    Re: Reading From stdin After Command Line Redirection Tim Daneliuk <tundra@tundraware.com> - 2013-10-23 19:09 -0500
      Re: Reading From stdin After Command Line Redirection Ben Finney <ben+python@benfinney.id.au> - 2013-10-24 14:53 +1100
        Re: Reading From stdin After Command Line Redirection Tim Daneliuk <tundra@tundraware.com> - 2013-10-23 23:36 -0500
        Re: Reading From stdin After Command Line Redirection Tim Daneliuk <tundra@tundraware.com> - 2013-10-23 23:39 -0500
        Re: Reading From stdin After Command Line Redirection Ben Finney <ben+python@benfinney.id.au> - 2013-10-24 15:54 +1100
          Re: Reading From stdin After Command Line Redirection Tim Daneliuk <tundra@tundraware.com> - 2013-10-24 06:58 -0500
          Re: Reading From stdin After Command Line Redirection Tim Daneliuk <tundra@tundraware.com> - 2013-10-24 06:58 -0500
            Re: Reading From stdin After Command Line Redirection Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-10-24 13:10 +0100
              Re: Reading From stdin After Command Line Redirection Tim Daneliuk <tundra@tundraware.com> - 2013-10-24 08:41 -0500
                Re: Reading From stdin After Command Line Redirection feedthetroll@gmx.de - 2013-10-24 07:36 -0700
                Re: Reading From stdin After Command Line Redirection Tim Daneliuk <tundra@tundraware.com> - 2013-10-24 09:43 -0500
              Re: Reading From stdin After Command Line Redirection Tim Daneliuk <tundra@tundraware.com> - 2013-10-24 08:41 -0500
                Re: Reading From stdin After Command Line Redirection Ethan Furman <ethan@stoneleaf.us> - 2013-10-24 07:30 -0700
      Re: Reading From stdin After Command Line Redirection Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-10-24 09:14 +0100
      Re: Reading From stdin After Command Line Redirection Ben Finney <ben+python@benfinney.id.au> - 2013-10-24 19:43 +1100
      Re: Reading From stdin After Command Line Redirection Tim Chase <python.list@tim.thechases.com> - 2013-10-24 05:45 -0500
      Re: Reading From stdin After Command Line Redirection Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-10-24 12:33 +0100
      Re: Reading From stdin After Command Line Redirection Ethan Furman <ethan@stoneleaf.us> - 2013-10-24 07:39 -0700
    Re: Reading From stdin After Command Line Redirection Tim Daneliuk <tundra@tundraware.com> - 2013-10-23 19:09 -0500
  Re: Reading From stdin After Command Line Redirection Chris Angelico <rosuav@gmail.com> - 2013-10-24 09:23 +1100

csiph-web