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


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

Re: Question About Command line arguments

Started byKurt Smith <kwmsmith@gmail.com>
First post2011-06-10 13:03 -0500
Last post2011-06-11 00:03 +0200
Articles 2 — 2 participants

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

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Question About Command line arguments Kurt Smith <kwmsmith@gmail.com> - 2011-06-10 13:03 -0500
    Re: Question About Command line arguments Hans Mulder <hansmu@xs4all.nl> - 2011-06-11 00:03 +0200

#7391 — Re: Question About Command line arguments

FromKurt Smith <kwmsmith@gmail.com>
Date2011-06-10 13:03 -0500
SubjectRe: Question About Command line arguments
Message-ID<mailman.91.1307729033.11593.python-list@python.org>
On Fri, Jun 10, 2011 at 12:58 PM, Mark Phillips
<mark@phillipsmarketing.biz> wrote:
> How do I write my script so it picks up argument from the output of commands
> that pipe input into my script?

def main():
    import sys
    print sys.stdin.read()

if __name__ == '__main__':
    main()

$ echo "fred" | python script.py
fred
$

[toc] | [next] | [standalone]


#7411

FromHans Mulder <hansmu@xs4all.nl>
Date2011-06-11 00:03 +0200
Message-ID<4df2949c$0$49177$e4fe514c@news.xs4all.nl>
In reply to#7391
On 10/06/11 20:03:44, Kurt Smith wrote:
> On Fri, Jun 10, 2011 at 12:58 PM, Mark Phillips
> <mark@phillipsmarketing.biz>  wrote:
>> How do I write my script so it picks up argument from the output of commands
>> that pipe input into my script?
>
> def main():
>      import sys
>      print sys.stdin.read()
>
> if __name__ == '__main__':
>      main()
>
> $ echo "fred" | python script.py
> fred
> $

$ cat script.py
def main():
     print raw_input()

if __name__ == '__main__':
     main()

$ echo "fred" | python script.py
fred
$


Hope this helps,

-- HansM


[toc] | [prev] | [standalone]


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


csiph-web