Question About Command line arguments

Hans Mulder hansmu at xs4all.nl
Fri Jun 10 18:03:08 EDT 2011


On 10/06/11 20:03:44, Kurt Smith wrote:
> On Fri, Jun 10, 2011 at 12:58 PM, Mark Phillips
> <mark at 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






More information about the Python-list mailing list