Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #73311
| From | Marko Rauhamaa <marko@pacujo.net> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: line to argv transformation |
| Date | 2014-06-16 13:59 +0300 |
| Organization | A noiseless patient Spider |
| Message-ID | <871tupp1bb.fsf@elektro.pacujo.net> (permalink) |
| References | <539EBF61.4050106@rece.vub.ac.be> <CAPTjJmqd74v013WwG2QrZP2y9N+gMk0TK5xT5-yy3=8gOuAs4g@mail.gmail.com> <539EC5EF.7040205@rece.vub.ac.be> <mailman.11082.1402915284.18130.python-list@python.org> |
Chris Angelico <rosuav@gmail.com>:
> def shell_split(cmd):
> return subprocess.check_output("""python -c 'import sys;
> print("\\0".join(sys.argv[1:]))' """+cmd,shell=True)[:-1].split(b"\0")
>
> You'll get back a list of byte strings, in any case. Feel free to pass
> them through a decode operation, or to incorporate a .decode() into
> the above stream, as you wish.
Now you are subject to the quirks of /bin/sh. For example, '*.xyz'
expands itself ('*.xyz') if there is no match in the current working
directory.
Moreover, you need to guard against arguments like
$(cat ~/.ssh/id_dsa)
which would spill the beans.
Marko
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: line to argv transformation Chris Angelico <rosuav@gmail.com> - 2014-06-16 20:41 +1000
Re: line to argv transformation Marko Rauhamaa <marko@pacujo.net> - 2014-06-16 13:59 +0300
Re: line to argv transformation Chris Angelico <rosuav@gmail.com> - 2014-06-16 21:25 +1000
csiph-web