471,306 Members | 884 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,306 software developers and data experts.

Parsing a commandline from within Python

Hello,

I am writing a commandline tool in Python which is often feed with lots of commandline arguments. In practice, the commandline already reached a critical length which is to long for Windows (some versions of Windows only support commandlines of up to 2047 characters). To work around this problem, wethought up the idea of bypassing the commandline into a file and then letting Python parse the content of the file the same way, the arguments in sys..argv are parsed.

Is there any buildin function which mimics the behavior of the standard commandline parser (generating a list of strings "foo bar" and "some text" from the commandline <"foo bar" "some text">)?

If not, do you have any other ideas how to handle this problem (increasing commandline length, xml files might be a way)?
Regards,

Andreas Huesgen

Viel oder wenig? Schnell oder langsam? Unbegrenzt surfen + telefonieren
ohne Zeit- und Volumenbegrenzung? DAS TOP ANGEBOT FÜR ALLE NEUEINSTEIGER
Jetzt bei Arcor: günstig und schnell mit DSL - das All-Inclusive-Paket
für clevere Doppel-Sparer, nur 34,95 € inkl. DSL- und ISDN-Grundgebühr!
http://www.arcor.de/rd/emf-dsl-2
Oct 11 '07 #1
2 1542
an*************@arcor.de wrote:
Is there any buildin function which mimics the behavior of the
standard commandline parser (generating a list of strings
"foo bar" and "some text" from the commandline
<"foo bar" "some text">)?
Try the shlex module::
>>import shlex
shlex.split('"foo bar" "some text"')
['foo bar', 'some text']

STeVe
Oct 11 '07 #2
>Is there any buildin function which mimics the behavior of the
standard commandline parser (generating a list of strings
"foo bar" and "some text" from the commandline
<"foo bar" "some text">)?

Try the shlex module::
>>import shlex
>>shlex.split('"foo bar" "some text"')
['foo bar', 'some text']
Thanks, that is exactly what i need.
Andreas Huesgen
Oct 11 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Gerrit Holl | last post: by
2 posts views Thread by Todd Moyer | last post: by
4 posts views Thread by Josef Wolf | last post: by
11 posts views Thread by Jean de Largentaye | last post: by
9 posts views Thread by ankitdesai | last post: by
2 posts views Thread by Toby | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.