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 20 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 1 of 2  [1] 2  Next page →


#57374 — Reading From stdin After Command Line Redirection

FromTim Daneliuk <tundra@tundraware.com>
Date2013-10-23 12:25 -0500
SubjectReading From stdin After Command Line Redirection
Message-ID<7cdlja-j3j2.ln1@ozzie.tundraware.com>
I have a program that runs like this:

   foo.py <inputfile

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.

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

[toc] | [next] | [standalone]


#57383

FromChris Angelico <rosuav@gmail.com>
Date2013-10-24 07:40 +1100
Message-ID<mailman.1425.1382560813.18130.python-list@python.org>
In reply to#57374
On Thu, Oct 24, 2013 at 4:25 AM, Tim Daneliuk <tundra@tundraware.com> wrote:
> I have a program that runs like this:
>
>   foo.py <inputfile
>
> 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.
>
> So, after I do .... = sys.stdin.readlines(), how to I reopen
> stdin in its nonredirected mode?

You fundamentally can't reopen "stdin", as that will just be your
input file. What you want to do is open the console (TTY) itself. What
platform are you on?

ChrisA

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


#57385

FromBen Finney <ben+python@benfinney.id.au>
Date2013-10-24 07:46 +1100
Message-ID<mailman.1427.1382561215.18130.python-list@python.org>
In reply to#57374
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

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


#57387

FromChris Angelico <rosuav@gmail.com>
Date2013-10-24 07:52 +1100
Message-ID<mailman.1428.1382561546.18130.python-list@python.org>
In reply to#57374
On Thu, Oct 24, 2013 at 7:46 AM, Ben Finney <ben+python@benfinney.id.au> wrote:
> 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.

There are times when this is correct behaviour - like asking for
passwords (SSH and sudo work like this).

ChrisA

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


#57388

Fromrandom832@fastmail.us
Date2013-10-23 17:01 -0400
Message-ID<mailman.1429.1382562518.18130.python-list@python.org>
In reply to#57374
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. It is an unusual thing to want
99% of the time, though.

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


#57390

FromBen Finney <ben+python@benfinney.id.au>
Date2013-10-24 09:20 +1100
Message-ID<mailman.1431.1382566824.18130.python-list@python.org>
In reply to#57374
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.

-- 
 \         “Broken promises don't upset me. I just think, why did they |
  `\                                         believe me?” —Jack Handey |
_o__)                                                                  |
Ben Finney

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


#57393

FromTim Daneliuk <tundra@tundraware.com>
Date2013-10-23 19:09 -0500
Message-ID<52686540.6000401@tundraware.com>
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]


#57400

FromBen Finney <ben+python@benfinney.id.au>
Date2013-10-24 14:53 +1100
Message-ID<mailman.1436.1382586805.18130.python-list@python.org>
In reply to#57393
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.

> 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.

Thank you for clarifying. 

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.

Rather, you should add to your program an option to allow specifying a
file to read, and present usage examples that don't redirect standard
input.

> 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.

That's the right solution, I'd say.

> 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.

Right. Congratulations for learning more about the design of the OS and
making a program that fits in well :-)

-- 
 \       “A lot of people are afraid of heights. Not me, I'm afraid of |
  `\                                           widths.” —Steven Wright |
_o__)                                                                  |
Ben Finney

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


#57403

FromTim Daneliuk <tundra@tundraware.com>
Date2013-10-23 23:36 -0500
Message-ID<mailman.1437.1382589426.18130.python-list@python.org>
In reply to#57400
On 10/23/2013 10:53 PM, Ben Finney wrote:
> Right. Congratulations for learning more about the design of the OS and
> making a program that fits in well:-)

It's only possible because, after some 30 years of doing this, I feel
very abelist ...

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

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


#57404

FromTim Daneliuk <tundra@tundraware.com>
Date2013-10-23 23:39 -0500
Message-ID<mailman.1438.1382589602.18130.python-list@python.org>
In reply to#57400
On 10/23/2013 10:53 PM, Ben Finney wrote:
> Congratulations for learning more about the design of the OS and
> making a program that fits in well

It's only because of some 30 years of doing this that I now
feel quite abelist ...

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

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


#57407

FromBen Finney <ben+python@benfinney.id.au>
Date2013-10-24 15:54 +1100
Message-ID<mailman.1440.1382590496.18130.python-list@python.org>
In reply to#57400
Tim Daneliuk <tundra@tundraware.com> writes:

> On 10/23/2013 10:53 PM, Ben Finney wrote:
> > Right. Congratulations for learning more about the design of the OS and
> > making a program that fits in well:-)
>
> It's only possible because, after some 30 years of doing this, I feel
> very abelist ...

You may be unaware, so I'll give the benefit of the doubt. To be ableist
is analogous with being sexist: a form of prejudicial behaviour against
disadvantaged groups.

You're free to express yourself however you like in your own space, but
in this community, we don't welcome ableist (nor sexist) behaviour.

-- 
 \       “Corporation, n. An ingenious device for obtaining individual |
  `\       profit without individual responsibility.” —Ambrose Bierce, |
_o__)                                   _The Devil's Dictionary_, 1906 |
Ben Finney

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


#57449

FromTim Daneliuk <tundra@tundraware.com>
Date2013-10-24 06:58 -0500
Message-ID<mailman.1467.1382615939.18130.python-list@python.org>
In reply to#57407
On 10/23/2013 11:54 PM, Ben Finney wrote:
> we don't welcome ableist (nor sexist) behaviour.

Well now I just feel so very awful ...

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

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


#57450

FromTim Daneliuk <tundra@tundraware.com>
Date2013-10-24 06:58 -0500
Message-ID<52690B59.7060004@tundraware.com>
In reply to#57407
On 10/23/2013 11:54 PM, Ben Finney wrote:
> we don't welcome ableist (nor sexist) behaviour.

Well now I just feel so very awful ...

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

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


#57451

FromOscar Benjamin <oscar.j.benjamin@gmail.com>
Date2013-10-24 13:10 +0100
Message-ID<mailman.1468.1382616682.18130.python-list@python.org>
In reply to#57450
On 24 October 2013 12:58, Tim Daneliuk <tundra@tundraware.com> wrote:
> On 10/23/2013 11:54 PM, Ben Finney wrote:
>>
>> we don't welcome ableist (nor sexist) behaviour.
>
> Well now I just feel so very awful ...

Please end this line of discussion. Ben is right: your comment was
entirely unnecessary and could easily offend.


Oscar

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


#57456

FromTim Daneliuk <tundra@tundraware.com>
Date2013-10-24 08:41 -0500
Message-ID<mailman.1471.1382622127.18130.python-list@python.org>
In reply to#57451
On 10/24/2013 07:10 AM, Oscar Benjamin wrote:
> On 24 October 2013 12:58, Tim Daneliuk <tundra@tundraware.com> wrote:
>> On 10/23/2013 11:54 PM, Ben Finney wrote:
>>>
>>> we don't welcome ableist (nor sexist) behaviour.
>>
>> Well now I just feel so very awful ...
>
> Please end this line of discussion. Ben is right: your comment was
> entirely unnecessary and could easily offend.
>
>
> Oscar
>


And his condescension was even more offensive.

But now I feel bad about myself and it's all your fault.

-- 
-----------------------------------------------------------------------
Tim Daneliuk

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


#57458

Fromfeedthetroll@gmx.de
Date2013-10-24 07:36 -0700
Message-ID<8f9cea5d-d4a5-4345-a2d0-e1d50615c2c9@googlegroups.com>
In reply to#57456
Am Donnerstag, 24. Oktober 2013 15:41:52 UTC+2 schrieb Tim Daneliuk:
> On 10/24/2013 07:10 AM, Oscar Benjamin wrote:
>> On 24 October 2013 12:58, Tim Daneliuk <tundra@tundraware.com> wrote:
>>> On 10/23/2013 11:54 PM, Ben Finney wrote:
>>>> we don't welcome ableist (nor sexist) behaviour.
>>> Well now I just feel so very awful ...
>> Please end this line of discussion. Ben is right: your comment was
>> entirely unnecessary and could easily offend.
>> Oscar
> And his condescension was even more offensive.
> But now I feel bad about myself and it's all your fault.
No it is not. You are the only one responsible for your feelings.
Or is it your fault, that I fell bad, because you feel bad?

Btw it's your feelings, that grade an impartial statement as condescension.
As my feelings grade your statements as extremely offending. And (to follow your arguments) that's your fault!

> ...
> Tim Daneliuk

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


#57459

FromTim Daneliuk <tundra@tundraware.com>
Date2013-10-24 09:43 -0500
Message-ID<b9onja-sm02.ln1@ozzie.tundraware.com>
In reply to#57458
On 10/24/2013 09:36 AM, feedthetroll@gmx.de wrote:
> Am Donnerstag, 24. Oktober 2013 15:41:52 UTC+2 schrieb Tim Daneliuk:
>> On 10/24/2013 07:10 AM, Oscar Benjamin wrote:
>>> On 24 October 2013 12:58, Tim Daneliuk <tundra@tundraware.com> wrote:
>>>> On 10/23/2013 11:54 PM, Ben Finney wrote:
>>>>> we don't welcome ableist (nor sexist) behaviour.
>>>> Well now I just feel so very awful ...
>>> Please end this line of discussion. Ben is right: your comment was
>>> entirely unnecessary and could easily offend.
>>> Oscar
>> And his condescension was even more offensive.
>> But now I feel bad about myself and it's all your fault.
> No it is not. You are the only one responsible for your feelings.
> Or is it your fault, that I fell bad, because you feel bad?
>
> Btw it's your feelings, that grade an impartial statement as condescension.
> As my feelings grade your statements as extremely offending. And (to follow your arguments) that's your fault!

Yeah ... definitely feel bad ... definitely...
  
-----------------------------------------------------------------------
Tim Daneliuk

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


#57457

FromTim Daneliuk <tundra@tundraware.com>
Date2013-10-24 08:41 -0500
Message-ID<526923A0.6080306@tundraware.com>
In reply to#57451
On 10/24/2013 07:10 AM, Oscar Benjamin wrote:
> On 24 October 2013 12:58, Tim Daneliuk <tundra@tundraware.com> wrote:
>> On 10/23/2013 11:54 PM, Ben Finney wrote:
>>>
>>> we don't welcome ableist (nor sexist) behaviour.
>>
>> Well now I just feel so very awful ...
>
> Please end this line of discussion. Ben is right: your comment was
> entirely unnecessary and could easily offend.
>
>
> Oscar
>


And his condescension was even more offensive.

But now I feel bad about myself and it's all your fault.

-- 
-----------------------------------------------------------------------
Tim Daneliuk

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


#57460

FromEthan Furman <ethan@stoneleaf.us>
Date2013-10-24 07:30 -0700
Message-ID<mailman.1472.1382626385.18130.python-list@python.org>
In reply to#57457
On 10/24/2013 06:41 AM, Tim Daneliuk wrote:
>
> But now I feel bad about myself and it's all your fault.

Really?

*plonk*

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


#57429

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2013-10-24 09:14 +0100
Message-ID<mailman.1451.1382602500.18130.python-list@python.org>
In reply to#57393
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've been diagnosed with Asperger, and have had 
the fun and games that goes with raising a youngster with Asperger who 
is also partially deaf.

-- 
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

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


Page 1 of 2  [1] 2  Next page →

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


csiph-web