Parsing a commandline from within Python

A

andreas.huesgen

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, we thought 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
 
S

Steven Bethard

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::
['foo bar', 'some text']

STeVe
 
A

Andreas Huesgen

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::
['foo bar', 'some text']

Thanks, that is exactly what i need.


Andreas Huesgen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top