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


Groups > comp.lang.python > #57374 > unrolled thread

Reading From stdin After Command Line Redirection

Started byTim Daneliuk <tundra@tundraware.com>
First post2013-10-23 12:25 -0500
Last post2013-10-24 09:23 +1100
Articles 6 on this page of 26 — 9 participants

Back to article view | Back to comp.lang.python


Contents

  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

Page 2 of 2 — ← Prev page 1 [2]


#57437

FromBen Finney <ben+python@benfinney.id.au>
Date2013-10-24 19:43 +1100
Message-ID<mailman.1459.1382604197.18130.python-list@python.org>
In reply to#57393
Mark Lawrence <breamoreboy@yahoo.co.uk> writes:

> On 24/10/2013 04:53, Ben Finney wrote:
> > Tim Daneliuk <tundra@tundraware.com> writes:
> >
> >> 'Easy there Rainman
> >
> > I'll thank you not to use mental deficiency as some kind of insult.
> > Calling someone “Rainman” is to use autistic people as the punchline
> > of a joke. We're a community that doesn't welcome such ableist
> > slurs.
>
> I saw no such insult.

Foprtunately, this forum is not all about you.

-- 
 \        “We must become the change we want to see.” —Mohandas Gandhi |
  `\                                                                   |
_o__)                                                                  |
Ben Finney

[toc] | [prev] | [next] | [standalone]


#57444

FromTim Chase <python.list@tim.thechases.com>
Date2013-10-24 05:45 -0500
Message-ID<mailman.1464.1382611406.18130.python-list@python.org>
In reply to#57393
On 2013-10-24 14:53, Ben Finney wrote:
> I think the request is incoherent: If you want to allow the user to
> primarily interact with the program, this is incompatible with also
> wanting to redirect standard input.

As a counter-example, might I suggest one I use regularly:

  gimme_stuff_on_stdout.sh | vim -

I want to use vim interactively, but I want it to read the
file-to-edit from stdin.

-tkc



[toc] | [prev] | [next] | [standalone]


#57447

FromOscar Benjamin <oscar.j.benjamin@gmail.com>
Date2013-10-24 12:33 +0100
Message-ID<mailman.1466.1382614452.18130.python-list@python.org>
In reply to#57393
On 24 October 2013 01:09, Tim Daneliuk <tundra@tundraware.com> wrote:
>
> Now that I think about it, as I recall from the prehistoric era of writing
> lots of assembler and C, if you use shell redirection, stdin shows
> up as a handle to the file

Yes this is true. A demonstration using seek (on Windows but it is the
same in this sense):

$ cat test.py
import sys
sys.stdin.seek(0)
print('Seeked fine without errors')
$ python test.py
Traceback (most recent call last):
  File "test.py", line 2, in <module>
    sys.stdin.seek(0)
IOError: [Errno 9] Bad file descriptor
$ python test.py < other.dat
Seeked fine without errors

> and there is no way to retrieve/reset it
> its default association with the tty/pty.  Since python is layered on
> top of this, I expect the same would be the case here as well.

I think it is true that you cannot restore the association but you can
just open the tty explicitly as described here:
http://superuser.com/questions/569432/why-can-i-see-password-prompts-through-redirecting-output

(I can't test that right now as it obviously doesn't work on Windows).


Oscar

[toc] | [prev] | [next] | [standalone]


#57461

FromEthan Furman <ethan@stoneleaf.us>
Date2013-10-24 07:39 -0700
Message-ID<mailman.1473.1382626928.18130.python-list@python.org>
In reply to#57393
On 10/24/2013 01:14 AM, Mark Lawrence wrote:
> On 24/10/2013 04:53, Ben Finney wrote:
>> Tim Daneliuk <tundra@tundraware.com> writes:
>>
>>> 'Easy there Rainman
>>
>> I'll thank you not to use mental deficiency as some kind of insult.
>> Calling someone “Rainman” is to use autistic people as the punchline of
>> a joke. We're a community that doesn't welcome such ableist slurs.
>
> I saw no such insult.

I don't know how wide-spread the movie is, but in the US "Rainman" is well-known.  Short synopsis:  younger brother 
finds out about older brother; older brother has mental challenges (I don't recall which one); they spend about a week 
together while younger brother tries to straighten out his life.  So unless you're talking about Native American dances 
it's an inappropriate moniker to apply to someone, particularly when you're being insulting.

And having said all that, we can have disagreements without name calling.

--
~Ethan~

[toc] | [prev] | [next] | [standalone]


#57396

FromTim Daneliuk <tundra@tundraware.com>
Date2013-10-23 19:09 -0500
Message-ID<mailman.1434.1382574076.18130.python-list@python.org>
In reply to#57390
On 10/23/2013 05:20 PM, Ben Finney wrote:
> random832@fastmail.us writes:
>
>> On Wed, Oct 23, 2013, at 16:52, Chris Angelico wrote:
>>> There are times when this is correct behaviour - like asking for
>>> passwords (SSH and sudo work like this).
>>
>> Less (or pagers generally, or an interactive text editor that allows
>> creating a file from standard input) would be another example of a
>> program where it makes sense to do this.
>
> You're both describing programs that read the console, which is not what
> the OP was asking for. The OP was asking about re-opening stdin after
> reaching EOF, which is incoherent as far as I understand it.
>
> I'm still waiting for the OP to clarify what they want to do.
>

'Easy there Rainman, the question is entirely coherent,
though it may not be achievable this way.  The goal of the
exercise was:

- Read a file the user specifies via command line redirection
- When the file is fully read, return to reading keyboard
   input with things like raw_input and get_pass which I believe
   use stdin as a source ... probably to avoid having to manually
   cope with ttys and ptys themselves. One of those two functions -
   I don't recall which - was giving me a problem with stdin redirected.

In the end, I broke down and added a command line parameter to
specify which file to read in so that stdin would be unaffected.

Now that I think about it, as I recall from the prehistoric era of writing
lots of assembler and C, if you use shell redirection, stdin shows
up as a handle to the file and there is no way to retrieve/reset it
its default association with the tty/pty.  Since python is layered on
top of this, I expect the same would be the case here as well.



-- 
----------------------------------------------------------------------------
Tim Daneliuk     tundra@tundraware.com
PGP Key:         http://www.tundraware.com/PGP/

[toc] | [prev] | [next] | [standalone]


#57391

FromChris Angelico <rosuav@gmail.com>
Date2013-10-24 09:23 +1100
Message-ID<mailman.1432.1382567040.18130.python-list@python.org>
In reply to#57374
On Thu, Oct 24, 2013 at 9:20 AM, Ben Finney <ben+python@benfinney.id.au> wrote:
> random832@fastmail.us writes:
>
>> On Wed, Oct 23, 2013, at 16:52, Chris Angelico wrote:
>> > There are times when this is correct behaviour - like asking for
>> > passwords (SSH and sudo work like this).
>>
>> Less (or pagers generally, or an interactive text editor that allows
>> creating a file from standard input) would be another example of a
>> program where it makes sense to do this.
>
> You're both describing programs that read the console, which is not what
> the OP was asking for. The OP was asking about re-opening stdin after
> reaching EOF, which is incoherent as far as I understand it.
>
> I'm still waiting for the OP to clarify what they want to do.

The OP did say "tty" and mentioned getpass.

ChrisA

[toc] | [prev] | [standalone]


Page 2 of 2 — ← Prev page 1 [2]

Back to top | Article view | comp.lang.python


csiph-web