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


Groups > comp.lang.python > #73336

Re: line to argv transformation

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <antoon.pardon@rece.vub.ac.be>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; '16,': 0.03; 'received:134': 0.05; 'session.': 0.07; 'variables': 0.07; 'assuming': 0.09; 'prefix': 0.09; 'subject:skip:t 10': 0.09; 'def': 0.12; 'systems.': 0.12; "wouldn't": 0.14; 'windows': 0.15; 'command,': 0.16; 'did.': 0.16; 'differs': 0.16; "he'd": 0.16; 'operation,': 0.16; 'splitting': 0.16; 'string:': 0.16; 'substitute': 0.16; 'too?': 0.16; 'variables,': 0.16; 'wrote:': 0.18; 'looked': 0.18; 'variable': 0.18; 'trying': 0.19; "hasn't": 0.19; 'split': 0.19; 'command': 0.22; '>>>': 0.22; 'example': 0.22; 'shell': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; 'byte': 0.24; 'case.': 0.24; 'mon,': 0.24; 'environment': 0.24; 'skip:" 30': 0.26; 'pass': 0.26; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'skip:p 30': 0.29; 'tim': 0.29; 'unix': 0.29; 'expansion': 0.30; 'asked': 0.31; 'too.': 0.31; '(although': 0.31; 'chase': 0.31; 'quite': 0.32; 'totally': 0.33; 'maybe': 0.34; "i'd": 0.34; 'could': 0.34; 'problem': 0.35; 'common': 0.35; 'skip:s 30': 0.35; 'something': 0.35; 'but': 0.35; 'done,': 0.36; 'done': 0.36; 'doing': 0.36; "didn't": 0.36; 'list': 0.37; '(i.e.,': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'commands': 0.60; 'most': 0.60; 'free': 0.61; 'course': 0.61; 'you.': 0.62; 'back': 0.62; "you'll": 0.62; 'more': 0.64; 'within': 0.65; 'incorporate': 0.68; 'line,': 0.68; 'behavior': 0.77; "it'd": 0.84; 'pardon': 0.84; 'wish.': 0.84; 'troublesome': 0.91
X-IronPort-Anti-Spam-Filtered true
X-IronPort-Anti-Spam-Result AqAEAILqn1OGuA9G/2dsb2JhbABahyXAPQGBJIR4AQEFI2YLGAICBSECAg8COAENEwYCAheIJ60NmSmFCReBKo1TFoJhgUwBA5pDhmOMdYNCag
Date Tue, 17 Jun 2014 09:17:14 +0200
From Antoon Pardon <antoon.pardon@rece.vub.ac.be>
User-Agent Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Icedove/24.5.0
MIME-Version 1.0
To python-list@python.org
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> <20140616055124.56ccd3c5@bigbox.christie.dr> <CAPTjJmpj3Ot5uW84=zOpF_G9wPwn3Pd+9Ni1etU_2_MWVn5utA@mail.gmail.com>
In-Reply-To <CAPTjJmpj3Ot5uW84=zOpF_G9wPwn3Pd+9Ni1etU_2_MWVn5utA@mail.gmail.com>
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.11101.1402989436.18130.python-list@python.org> (permalink)
Lines 37
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1402989436 news.xs4all.nl 2868 [2001:888:2000:d::a6]:52065
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:73336

Show key headers only | View raw


On 16-06-14 13:09, Chris Angelico wrote:
> On Mon, Jun 16, 2014 at 8:51 PM, Tim Chase
> <python.list@tim.thechases.com> wrote:
>> 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.
> Well, his example commands began "ls", which is a common Unix command,
> but isn't present on most Windows systems. If he'd started out with
> something that looked more Windowsish, I'd totally understand - you
> start with a single line, and you need to do what the cmd.exe shell
> hasn't done for you. (Although splitting is done, so it still wouldn't
> be quite as clear.) But he said "treated as a command line". So that's
> exactly what I did. :) He didn't ask about globbing, he asked about
> doing what the shell does... maybe he wants variable expansion too?

That would be interresting too. The problem with your solution would be
that it would only substitute environment variables, and not "shell variables"
within the interactive session. Of course I could use os.putenv to put all
those variables in the environment but that might have troublesome effects
on other subprocesses.

-- 
Antoon Pardon

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


Thread

Re: line to argv transformation Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2014-06-17 09:17 +0200

csiph-web