Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #73314
| Date | 2014-06-16 05:51 -0500 |
|---|---|
| From | Tim Chase <python.list@tim.thechases.com> |
| Subject | Re: line to argv transformation |
| References | <539EBF61.4050106@rece.vub.ac.be> <CAPTjJmqd74v013WwG2QrZP2y9N+gMk0TK5xT5-yy3=8gOuAs4g@mail.gmail.com> <539EC5EF.7040205@rece.vub.ac.be> <CAPTjJmq3632=BXUYmd-EEUtaKAVj=pQQ2m-uz_Fd_PoQT1agQg@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.11085.1402917709.18130.python-list@python.org> (permalink) |
On 2014-06-16 20:41, Chris Angelico wrote:
> Oops! I made the cardinal error of trying in one and assuming it'd
> work in both. Just needs a b prefix on the split string:
>
> 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.
Tested on Win32? The behavior of "shell expansion" on Windows
cmd.exe differs from most *nix shells (i.e., it *doesn't* expand, so
you have to do it yourself), so Antoon would need to describe the
desired behavior on Win32.
-tkc
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: line to argv transformation Tim Chase <python.list@tim.thechases.com> - 2014-06-16 05:51 -0500
csiph-web