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


Groups > comp.lang.python > #7398

Re: Question About Command line arguments

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!194.109.133.84.MISMATCH!newsfeed.xs4all.nl!newsfeed5.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.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'arguments': 0.05; 'mrab': 0.05; 'prints': 0.07; 'python': 0.08; '__name__': 0.09; 'arguments,': 0.09; 'arguments.': 0.09; 'fred': 0.09; 'none:': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'statement.': 0.09; 'underlying': 0.09; 'pm,': 0.10; 'output': 0.11; 'syntax': 0.11; 'def': 0.12; 'am,': 0.14; 'wrote:': 0.14; '"__main__":': 0.16; '"echo': 0.16; '`echo': 0.16; 'enigma': 0.16; 'input.': 0.16; 'kern': 0.16; 'phillips': 0.16; 'picks': 0.16; 'received:216.62': 0.16; 'received:216.62.213': 0.16; 'received:enthought.com': 0.16; '"python': 0.16; 'argument': 0.16; 'input': 0.17; 'processed': 0.19; 'shell': 0.19; 'command': 0.19; 'header:In-Reply-To:1': 0.21; 'appropriate': 0.21; "aren't": 0.22; 'wrote': 0.22; 'fri,': 0.23; 'subject:Question': 0.25; 'script': 0.27; 'problem': 0.28; 'interpret': 0.29; 'second': 0.30; 'usage': 0.32; 'header:X-Complaints-To:1': 0.32; 'to:addr:python-list': 0.33; 'there': 0.35; 'header:User-Agent:1': 0.35; 'received:org': 0.38; 'run': 0.38; 'though': 0.38; 'subject:: ': 0.38; 'case,': 0.39; 'skip:s 20': 0.39; 'attempt': 0.39; 'header:Mime-Version:1': 0.39; 'to:addr:python.org': 0.39; 'your': 0.60; 'world': 0.63; 'our': 0.63; 'believe': 0.66; 'subject:About': 0.68; 'subject:line': 0.73; 'eco': 0.91
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Robert Kern <robert.kern@gmail.com>
Subject Re: Question About Command line arguments
Date Fri, 10 Jun 2011 14:27:10 -0500
Organization The Church of Last Thursday
References <BANLkTi==QHd+5C=xf+2Re1Mh4V6Hk972hg@mail.gmail.com> <4DF25738.2020704@mrabarnett.plus.com> <BANLkTimHfZK=FsbSs4BOX8dU=mt2bVGV9A@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host outbound.enthought.com
User-Agent Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10
In-Reply-To <BANLkTimHfZK=FsbSs4BOX8dU=mt2bVGV9A@mail.gmail.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.103.1307734048.11593.python-list@python.org> (permalink)
Lines 49
NNTP-Posting-Host 82.94.164.166
X-Trace 1307734048 news.xs4all.nl 49181 [::ffff:82.94.164.166]:35767
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:7398

Show key headers only | View raw


On 6/10/11 12:58 PM, Mark Phillips wrote:
> On Fri, Jun 10, 2011 at 10:41 AM, MRAB <python@mrabarnett.plus.com
> <mailto:python@mrabarnett.plus.com>> wrote:
>
>     On 10/06/2011 18:21, Mark Phillips wrote:
>
>         I have a script that processes command line arguments
>
>         def main(argv=None):
>              syslog.syslog("Sparkler stared processing")
>              if argv is None:
>                  argv = sys.argv
>              if len(argv) != 2:
>                  syslog.syslog(usage())
>              else:
>                  r = parseMsg(sys.argv[1])
>                  syslog.syslog(r)
>              return 0
>
>         if __name__ == "__main__":
>              sys.exit(main())
>
>         When I run "python myscript fred" it works as expected - the argument
>         fred is processed in parseMsg as sys.arv[1]
>
>         When I run "echo fred | python myscript" the script thinks there are no
>         arguments, so it prints out the usage statement.
>
>         Is the problem with the echo command, or how I wrote my script?
>
>     In the second case, there aren't any arguments. The echo command is
>     writing "fred" to its standard output, which is attached to your
>     script's standard input.
>
> How do I write my script so it picks up argument from the output of commands
> that pipe input into my script?

You may want to just use the appropriate shell syntax instead:

   $ python myscript `echo fred`

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco

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


Thread

Re: Question About Command line arguments Robert Kern <robert.kern@gmail.com> - 2011-06-10 14:27 -0500

csiph-web